Display QImage with QtGui

后端 未结 5 1439
忘了有多久
忘了有多久 2020-12-02 09:01

I am new to Qt, and I am trying to create a simple GUI Application that displays an image once a button has been clicked on.

I can read the image in a QImage

5条回答
  •  猫巷女王i
    2020-12-02 09:48

    One common way is to add the image to a QLabel widget using QLabel::setPixmap(), and then display the QLabel as you would any other widget. Example:

    #include 
    
    int main(int argc, char *argv[])
    {
      QApplication app(argc, argv);
      QPixmap pm("your-image.jpg");
      QLabel lbl;
      lbl.setPixmap(pm);
      lbl.show();
      return app.exec();
    }
    

提交回复
热议问题