使用QtGui显示QImage [英] Display QImage with QtGui
问题描述
我是Qt的新手,我试图创建一个简单的GUI应用程序,一旦点击按钮就显示图像。
我可以读取图像在一个 QImage
对象,但是有什么简单的方法来调用一个Qt函数,以 QImage
作为输入,并显示它?
谢谢所有,我找到了如何做,这是Dave和谢尔盖: / p>
我使用QT Creator:
在主GUI窗口中使用拖放GUI创建,例如myLabel)
在按钮的回调(点击)中,使用指向用户界面窗口的(* ui)指针执行以下操作:
void MainWindow :: on_pushButton_clicked()
{
QImage imageObject;
imageObject.load(imagePath);
ui-> myLabel-> setPixmap(QPixmap :: fromImage(imageObject));
//或者直接设置Pixmap使用另一种方式
QPixmap pixmapObject(imagePath);
ui-> myLabel2-> setPixmap );
}
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
object, but is there any simple way to call a Qt function that takes the QImage
as an input, and displays it?
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);
}
这篇关于使用QtGui显示QImage的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!