QLable控件

Qlabel可以载入图片,文字

设置label控件内容的自适应方法是

setScaledContents

轮播:时钟控件QTimer

QPixmap承载图片、配置图片容器

过程:1.创建QPixmap对象

2.在QLable中载入QPixmap对象

3.通过时钟控件修改图片路径

快捷键:alt+/ 可以代码提示

新建一个QT资源类

将图片添加进来

#ifndef TEST_H
#define TEST_H

#include <QMainWindow>
#include <QWidget>
#include <QLabel>
#include <QPixmap>
#include <QTimer>
#include <QString>

class test : public QMainWindow
{
    Q_OBJECT

public:
    test(QWidget *parent = 0);
    ~test();
private:
    QLabel lblimg;
    QTimer *timer1;
    QPixmap *pm;
    int num;
private slots:
    void myfunc1();
};

#endif // TEST_H
#include "test.h"
#include <QLabel>

test::test(QWidget *parent)
    : QMainWindow(parent)
{
    this->setGeometry(0,0,600,600);
    num =1;
    pm = new QPixmap();
    pm->load(":/wsq/image/oa"+QString::number(num)+".jpg");   //数值转字符串
    lblimg.setPixmap(*pm);  //虽然写的是相对,(但实际上绝对路径是跟着项目来的)相当于以QPixmap这个类为模板创建了对象
    lblimg.setScaledContents(true);//内部内容自适应
    lblimg.setStyleSheet("border:10px solid red;");
    lblimg.setGeometry(100,100,300,300);
    lblimg.setParent(this);//控件加入
    timer1 = new QTimer(this);
    connect(timer1,SIGNAL(timeout()),this,SLOT(myfunc1()));
    timer1->start(1000);
    //lblimg.resize(1920,1080);
    //文字链接
    lbldesc=new QLabel(this);
    lbldesc->setText("<a href='https://i.cnblogs.com/posts/edit'>WSQ的博客</a>");
    lbldesc->setOpenExternalLinks(true);




}

test::~test()
{


}

void test::myfunc1()
{
    num++;
    if(num>3)num=1;
    pm->load(":/wsq/image/oa"+QString::number(num)+".jpg");
    lblimg.setPixmap(*pm);


}
setStyleSheet

设置图形界面的外观

 

posted @ 2021-10-21 01:16  wsq1219  阅读(133)  评论(0编辑  收藏  举报