使用 QtGui 显示 QImage [英] Display QImage with QtGui

查看:123
本文介绍了使用 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的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆