简体   繁体   English

QGraphicsObject不显示QPixmap

[英]QGraphicsObject doesn't display QPixmap

I'm developing a very simple application on win7 and running on win8. 我正在win7上开发一个非常简单的应用程序,并在win8上运行。 When I run on win7 it shows the pixmap drawn by my QGraphicsObject subclass. 当我在win7上运行时,它显示了我的QGraphicsObject子类绘制的像素图。 However when I copy the exe and dll's to the my tablet it doesn't show the pixmap but everything else is the same. 但是,当我将exe和dll复制到我的平板电脑时,它不会显示像素图,但其他所有内容都相同。

Another problem is when I quit the application it says unexpectedly closed. 另一个问题是,当我退出应用程序时,它说意外关闭。

Here are the related parts 这是相关的部分

myImage::myImage(QGraphicsObject *parent) :
QGraphicsObject(parent)
{
    pxm = new QPixmap("://images/flower.jpg");
    setScale(0.5);
}

QRectF myImage::boundingRect() const
{
    QRectF rect(0,0,pxm->width(),pxm->height());
    return rect;
}

void myImage::paint( QPainter* painter,
                     const QStyleOptionGraphicsItem* /*option*/,
                     QWidget* /*widget*/ )
{
    painter->drawPixmap( 0, 0, pxm->width(), pxm->height(), *pxm );
}

And here is the main function 这是主要功能

int main(int argc, char *argv[])
{
    QApplication app(argc, argv);

    QGraphicsScene scene;

    myImage img;
    scene.addItem(&img);

    QGraphicsView view(&scene);

    QWidget window;
    window.setFixedHeight(400);
    window.setFixedWidth(500);
    window.setSizePolicy(QSizePolicy::Fixed,QSizePolicy::Fixed);

    QPushButton button("Quit");
    QObject::connect(&button,SIGNAL(clicked()),&app,SLOT(quit()));

    QVBoxLayout layout;
    layout.addWidget(&view);
    layout.addWidget(&button);

    window.setLayout(&layout);
    window.show();

    return app.exec();
}

The problem here is that you're using a jpeg image, which isn't native to Qt. 这里的问题是您正在使用jpeg图像,它不是Qt的本机。 In the installation of Qt you'll find a plugins folder with a folder called "imageformats". 在Qt的安装中,您将找到一个名为“ imageformats”的文件夹文件夹。 If you copy the folder of libraries to the path of the executable (assuming Windows), then this should work. 如果将库的文件夹复制到可执行文件的路径(假定为Windows),则应该可以。 A similar discussion is here . 这里有一个类似的讨论。

Alternatively, use a different image format to jpeg. 或者,使用其他图像格式来jpeg。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM