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)
归档时间: |
|
查看次数: |
22082 次 |
最近记录: |