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


基础教程推荐
- 如何通过C程序打开命令提示符Cmd 2022-12-09
- 如何在 C++ 中初始化静态常量成员? 2022-01-01
- 如何检查GTK+3.0中的小部件类型? 2022-11-30
- 在 C++ 中计算滚动/移动平均值 2021-01-01
- 这个宏可以转换成函数吗? 2022-01-01
- 静态库、静态链接动态库和动态链接动态库的 .lib 文件里面是什么? 2021-01-01
- C++结构和函数声明。为什么它不能编译? 2022-11-07
- 如何将 std::pair 的排序 std::list 转换为 std::map 2022-01-01
- 我有静态或动态 boost 库吗? 2021-01-01
- 常量变量在标题中不起作用 2021-01-01