[Solved]QGraphicsView - no QPixmap shown load from resources (Linux)



  • Hi All,

    may I stay on the tube - but I cannot display a QPixmap within a Dialog Window ..
    and stuck's for a couple of days. I use the QtDesigner to create the Dialog.
    No Errors show in the qDebug output.
    Just have a review below. May someone can open my eyes.

    @
    AboutDialog::AboutDialog(QWidget *parent)
    : QDialog(parent)
    {
    QGraphicsScene scene;
    QString resourcePath = ":/images/about.png";

    setupUi(this);

    if( ! QFile::exists(resourcePath) )
    {
    qDebug("*** Error - Resource path not found : "%s"", resourcePath.toLatin1().data());
    }
    else {

    QPixmap p1(resourcePath);
    
    if ( p1.isNull() ) {
      qDebug("*** Error - Null QPixmap");
    }
    else {
      QGraphicsPixmapItem *item_p1 = scene.addPixmap(p1);
      item_p1->setVisible(true);
      //QGraphicsTextItem *item_txt = scene.addText("APTool v1.0");
      //item_txt->setVisible(true);
      gvViewPort->setScene(&scene);
      gvViewPort->show();
    }
    

    }
    }
    @

    @

    QGraphicsView *gvViewPort;

    void setupUi(QDialog *About)
    {
        if (About->objectName().isEmpty())
            About->setObjectName(QString::fromUtf8("About"));
        About->resize(400, 300);
        QIcon icon;
        icon.addFile(QString::fromUtf8(":/images/gts.png"), QSize(), QIcon::Normal, QIcon::Off);
        About->setWindowIcon(icon);
        About->setModal(true);
        gvViewPort = new QGraphicsView(About);
        gvViewPort->setObjectName(QString::fromUtf8("gvViewPort"));
        gvViewPort->setGeometry(QRect(40, 10, 312, 239));
    

    ...
    @

    and all I see is a white frame.

    !http://www.gtsys.com.hk:8080/~chris/Screenshot-About.png(About-dialog-no-pixmap)!

    thanks.
    Chris



  • Solved:

    The QGraphicsScene scene should be a private member of the class.

    private:
    QGraphicsScene *scene;

    and in the constructor
    scene = new QGraphicsScene();

    Cheers



  • [quote author="ruehlchr" date="1306816114"]Solved:

    The QGraphicsScene scene should be a private member of the class.

    private:
    QGraphicsScene *scene;

    and in the constructor
    scene = new QGraphicsScene();

    Cheers
    [/quote]

    You probably can do in the constructor:
    @
    QGraphicsScene *scene = new QGraphicsScene();

    @


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.