Qt jpg image display

Qt jpg image display

Asked on December 20, 2018 in Qt.
Add Comment


  • 3 Answer(s)

    Qt jpg code is given below:

    #include ...
     
    int main(int argc, char *argv[])
    {
       QApplication a(argc, argv);
       QGraphicsScene scene;
       QGraphicsView view(&scene);
       QGraphicsPixmapItem item(QPixmap("c:\\test.png"));
       scene.addItem(&item);
       view.show();
       return a.exec();
    }
    

    For more formats see this http://qt-project.org/doc/qt-5.0/qtgui/qpixmap.html#reading-and-writing-image-files

    Answered on December 20, 2018.
    Add Comment

    Try this below code:

    They attach the image (as a pixmap) to a label then add the layout.

    ...
    QPixmap image("blah.jpg");
     
    QLabel imageLabel = new QLabel();
    imageLabel.setPixmap(image);
     
    mainLayout.addWidget(imageLabel);
    ...
    

    In qt for  java the syntax is different, but the theory is the same.

    Answered on December 20, 2018.
    Add Comment

     

    The explanations is given :

       Drop the image into  a widget withouth the complexity of the graphics API, and  just to create a new QWidget and set the background with StyleSheets.

    MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent)
    { 
      ...
      QWidget *pic = new QWidget(this);
      pic->setStyleSheet("background-image: url(test.png)");
      pic->setGeometry(QRect(50,50,128,128));
      ...
    }
    

     

    Answered on December 20, 2018.
    Add Comment


  • Your Answer

    By posting your answer, you agree to the privacy policy and terms of service.