Display QImage with QtGui(使用 QtGui 显示 QImage)
问题描述
我是 Qt 的新手,我正在尝试创建一个简单的 GUI 应用程序,该应用程序在单击按钮后显示图像.
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.
我可以在 QImage 对象中读取图像,但是有什么简单的方法可以调用 Qt 函数,将 QImage 作为输入并显示它?
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?
推荐答案
谢谢大家,我找到了方法,和 Dave 和 Sergey 一样:
Thanks All, I found how to do it, which is the same as Dave and Sergey:
我正在使用 QT Creator:
I am using QT Creator:
在主 GUI 窗口中使用拖放 GUI 创建并创建标签(例如myLabel")
In the main GUI window create using the drag drop GUI and create label (e.g. "myLabel")
在按钮(单击)的回调中,使用指向用户界面窗口的 (*ui) 指针执行以下操作:
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的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:使用 QtGui 显示 QImage
				
        
 
            
        - 如何提取 __VA_ARGS__? 2022-01-01
 - XML Schema 到 C++ 类 2022-01-01
 - 将函数的返回值分配给引用 C++? 2022-01-01
 - 哪个更快:if (bool) 或 if(int)? 2022-01-01
 - 使用 __stdcall & 调用 DLLVS2013 中的 GetProcAddress() 2021-01-01
 - DoEvents 等效于 C++? 2021-01-01
 - 将 hdc 内容复制到位图 2022-09-04
 - GDB 不显示函数名 2022-01-01
 - 从父 CMakeLists.txt 覆盖 CMake 中的默认选项(...)值 2021-01-01
 - OpenGL 对象的 RAII 包装器 2021-01-01
 
						
						
						
						
						