在Qt中以编程方式设置QLabel的像素图
Programatically setting the pixmap of a QLabel in Qt
我们用来显示图片的小部件是一个QLabel。我们可以直接从QtCreator中完成,通过设置它的pixmap属性。
我们应该首先创建一个资源文件,然后将图像添加到该资源文件。要创建一个Qt资源文件,我们进入菜单:文件> Qt> Qt资源文件。
我们可以使用Qt Creator来设置QLabel的映像…
但是我想根据用户
的一些输入来改变PIC我试着做以下事情:
#include "form1.h"
#include "form.h"
#include "ui_form.h"
#include "ui_form1.h"
Form::Form(QWidget *parent) :
QWidget(parent),
ui(new Ui::Form)
{
ui->setupUi(this);
QPixmap * mypix = new QPixmap(":/karim/test.png");
ui->label->setPixmap(mypix);
delete mypix;
}
但是我得到了这个错误
..Projectform.cpp: In constructor 'Form::Form(QWidget*)':
..Projectform.cpp:12: error: no matching function for call to 'QLabel::setPixmap(QPixmap*&)'
c:QtSDKSimulatorQtmingwinclude/QtGui/qlabel.h:123: note: candidates are: void QLabel::setPixmap(const QPixmap&)
您要使用的方法的签名是
setPixmap (const QPixmap &)
但是你传递的是一个指针。试试用一个值来代替。
QPixmap mypix (":/karim/test.png");
ui->label->setPixmap(mypix);
相关文章:
- 如何在不产生任何垃圾的情况下获得C中的像素
- 在C++中使用GDAL可以将图像的像素坐标转换为lat,long吗
- 如何在24位SDL_Surface上设置像素的颜色
- 如何从SDL_Surface获取特定像素的颜色
- 如何将CMSampleBufferRef/CIImage/UIImage转换为像素,例如uint8_t[]
- 在C++中查找像素 RGB 数据的最快方法是什么?
- 是否可以从 OpenGL 缓冲区获取原始大小的像素?
- 选择基于另一个垫子的非零像素的cv::Mat的一部分?
- 如何使用 sdl2 快速绘制像素网格?
- 如何在C++中进行像素操作? - Linux
- 他们如何将红外锁定像素转换为镜头前方 1m 的正常平面上的位置
- 访问随机图像像素的快速方法,最多一次
- OpenCV 像素访问点与 at() - 不同的值
- 如何使用 freetype2 访问单色位图中的像素状态
- 尝试渲染像素坐标时,简单线条渲染失败
- 如何在 QLabel 中以像素为单位放置颜色数据
- 在Qt中以编程方式设置QLabel的像素图
- 在QT框架中设置QLabel的像素图
- 如何将QLabel的大小设置为其像素图中图像的大小?
- 无法引用QLabel的像素图