Tha*_*nga 13 qt qimage qgraphicsscene
我对Qt很新.我在插入QImage场景时遇到了麻烦.有人可以告诉我如何添加QImage到QGraphicsScene?
Ste*_*fen 16
为此,您将使用QGraphicsPixmapItem您添加到场景中的任何其他内容QGraphicsItem.
该QGraphicsPixmapItem可以用初始化QPixmap这是一个位图的依赖于设备的表示,你可以从一个得到它QImage与静态函数例如QPixmap::fromImage().
更新(示例代码)
#include <QtGlobal>
#if QT_VERSION >= 0x050000
#include <QtWidgets>
#else
#include <QtGui>
#endif
int main(int argc, char *argv[]) {
QApplication a(argc, argv);
QImage image("test.png");
QGraphicsPixmapItem item( QPixmap::fromImage(image));
QGraphicsScene* scene = new QGraphicsScene;
scene->addItem(&item);
QGraphicsView view(scene);
view.show();
return a.exec();
}
Run Code Online (Sandbox Code Playgroud)