介绍
QLabel小部件提供文本或图像显示,没有提供用户交互功能。
UI属性介绍
textFormat:可以设置换行模式,如:PlanText模式下,在一个字符中加入“\n”后就可以换行
pixmap:选择图片
scaledContents:会根据图片的大小进行缩小
选中:
没选中:
wordWrap:是否根据空格换行
margin:左界限
openEnternalLinks:是否可以打开外在的链接
QLabel可以包含以下任何内容类型:
Content | Setting |
Plain text | Pass a QString to setText(). |
Rich text | Pass a QString that contains rich text to setText(). |
A pixmap | Pass a QPixmap to setPixmap(). |
A movie | Pass a QMovie to setMovie(). |
A number | Pass an int or a double to setNum(), which converts the number to plain text. |
Nothing | The same as an empty plain text. This is the default. Set by clear(). |
函数接口介绍
setText()设置一个显示文本
setPixmap()设置一个图像
setMovie设置一个动图
实例代码:
实现添加动态图
QMovie * lableMovie = new QMovie("://image/timg.gif");
ui->label->setMovie(lableMovie);
ui->label->setFixedSize(180, 180);
ui->label->setScaledContents(true); //不要缩放
lableMovie->start(); //开始显示
注意:lable主要用来作为显示,最好设置为可交互属性。