How to draw a QPoint on a QGraphicsView/Scene

左心房为你撑大大i 提交于 2019-12-12 05:58:36

问题


It's really not clear to me how to simply draw a 2d point in QT. I want it to overlay a QPixmap item, but every piece of documentation I find talks about drawing polygons with brushes.

Thanks in advance -


回答1:


From Qt's documentation:

QImage is designed and optimized for I/O, and for direct pixel access and manipulation, while QPixmap is designed and optimized for showing images on screen.

So if you have a QPixmap, convert it to QImage and then use QImage::setPixel:

QImage image = pixmap->toImage();
image.setPixel(2, 4, 0x0000ff);
ui->label->setPixmap(QPixmap::fromImage(image)); // show the image in a label


来源:https://stackoverflow.com/questions/3602152/how-to-draw-a-qpoint-on-a-qgraphicsview-scene

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!