Display QImage with QtGui

后端 未结 5 1437
忘了有多久
忘了有多久 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条回答
  •  星月不相逢
    2020-12-02 09:49

    Thanks All, I found how to do it, which is the same as Dave and Sergey:

    I am using QT Creator:

    In the main GUI window create using the drag drop GUI and create label (e.g. "myLabel")

    In the callback of the button (clicked) do the following using the (*ui) pointer to the user interface window:

    void MainWindow::on_pushButton_clicked()
    {
         QImage imageObject;
         imageObject.load(imagePath);
         ui->myLabel->setPixmap(QPixmap::fromImage(imageObject));
    
         //OR use the other way by setting the Pixmap directly
    
         QPixmap pixmapObject(imagePath");
         ui->myLabel2->setPixmap(pixmapObject);
    }
    

提交回复
热议问题