【问题标题】:Qt PNG image not displayingQt PNG图像不显示
【发布时间】:2013-04-09 17:01:35
【问题描述】:

我只是无法显示 png 图像,我检查它是否正确加载,但我的空白画布上没有显示任何内容。第三个用于显示图像。有人可以快速浏览一下吗?谢谢。

QImage * QI = new QImage;
bool Check = QI->load("test.png");
QGraphicsPixmapItem * QII = new QGraphicsPixmapItem(QPixmap::fromImage(*QI));

QRect ImagePanelArea1(0, MenuBarHeight, 
                      ScreenWidth / 3, (ScreenHeight / 2) - MenuBarHeight);
QRect ImagePanelArea2(ScreenWidth / 3, MenuBarHeight, 
                      ScreenWidth / 3, (ScreenHeight / 2) - MenuBarHeight);
QRect ImagePanelArea3((ScreenWidth / 3) * 2, MenuBarHeight, 
                      ScreenWidth / 3, (ScreenHeight / 2) - MenuBarHeight);

QGraphicsScene * QGS1 = new QGraphicsScene(ImagePanelArea1, this);
QGraphicsScene * QGS2 = new QGraphicsScene(ImagePanelArea2, this);
QGraphicsScene * QGS3 = new QGraphicsScene(ImagePanelArea3, this); 
QGS3->addItem(QII);

QGraphicsView * QGV1 = new QGraphicsView(QGS1, this); 
QGV1->setGeometry(ImagePanelArea1); 
QGV1->show();
QGraphicsView * QGV2 = new QGraphicsView(QGS2, this); 
QGV2->setGeometry(ImagePanelArea2); 
QGV2->show();
QGraphicsView * QGV3 = new QGraphicsView(QGS3, this); 
QGV3->setGeometry(ImagePanelArea3); QGV3->show();

【问题讨论】:

  • 那些qt镜像库你都安装了吗?默认不包含svg、png等的支持库。
  • 什么意思?我刚刚安装了 qt 安装程序我不知道对不起:(
  • 看看能不能找到qtsvg4.dll等图片库。
  • 我有一个名为 qtsvg 的文件夹,其中包含 src 文件。

标签: qt qimage qpixmap


【解决方案1】:

您确定您的项目不在您的场景之外QGS3

QII 位于(0;0) 位置。场景的QRect 定义在点((ScreenWidth / 3) * 2, MenuBarHeight) 和点(ScreenWidth / 3, (ScreenHeight / 2) - MenuBarHeight) 之间。

因此,如果您的图片小于(ScreenWidth / 3) * 2,您的商品将不可见。

【讨论】:

  • 我的图片是64x64像素,为什么不显示?我的意思是我的场景视图上有边框,所以我认为如果图片比它们大,则只需滚动图片即可。
猜你喜欢
  • 2011-02-28
  • 1970-01-01
  • 2014-04-29
  • 1970-01-01
  • 2021-12-09
  • 2019-08-10
  • 1970-01-01
  • 1970-01-01
  • 2015-05-19
相关资源
最近更新 更多