Qt:显示类控件

一、Lable

1、属性列表

2、代码示例

将一个狗头图片铺满label,并且将label随着窗口的大小进行调节

cpp 复制代码
#include "widget.h"
#include "ui_widget.h"
#include"QResizeEvent"
#include"QPixmap"
Widget::Widget(QWidget *parent)
    : QWidget(parent)
    , ui(new Ui::Widget)
{
    ui->setupUi(this);
    QPixmap pixmap(":/dog.png");
    ui->label->setPixmap(pixmap);
    //将图片平铺到label里
    ui->label->setScaledContents(true);
}

Widget::~Widget()
{
    delete ui;
}

void Widget::resizeEvent(QResizeEvent *event)
{
    //重写resizeEvent函数
    ui->label->setGeometry(0,0,event->size().width(),event->size().height());
    qDebug()<<event->size()<<ui->label->size();
}

二、LCD number

1、属性列表

2、代码示例

倒计时10秒

cpp 复制代码
#include "widget.h"
#include "ui_widget.h"
#include "QTimer"
Widget::Widget(QWidget *parent)
    : QWidget(parent)
    , ui(new Ui::Widget)
{
    ui->setupUi(this);
    Widget::timer=new QTimer(this);
    ui->lcdNumber->display(10);
    timer->setInterval(1000);
    timer->start();
    connect(timer,&QTimer::timeout,this,&Widget::updateTime);
}

Widget::~Widget()
{
    delete ui;

}

void Widget::updateTime()
{
    int value=ui->lcdNumber->value();
    if(value<=0)
    {
        this->timer->stop();
        return ;
    }
    ui->lcdNumber->display(value-1);
}
相关推荐
SomeOtherTime11 小时前
Rust所有权(AI回答)
开发语言·后端·rust
Easyhood11 小时前
Android 开发入门实践(十四):Compose 副作用入门与四个常用 API
android·开发语言·kotlin·android jetpack·compose
白杨尚青12 小时前
C++进阶篇(六):map 和 set 的模拟实现——用红黑树封装 mymap/myset(迭代器 + operator[])
开发语言·c++·迭代器·stl·set·map·红黑树
饮水桶_T16 小时前
JAVA IO流笔记
开发语言·数据结构·算法
Felven18 小时前
C. Brr Brrr Patapim
c语言·开发语言
路溪非溪19 小时前
python标准库使用总结
开发语言·python
SomeOtherTime21 小时前
Rust 面向对象介绍(AI回答)
开发语言·python·rust
zh_xuan21 小时前
kotlin常见面试题
开发语言·kotlin·面试题
草莓熊Lotso1 天前
【C++ 基于微服务的即时通讯系统】文件存储子服务实战:UUID生成、文件IO封装与全接口单元测试
开发语言·网络·数据库·c++·微服务·架构·单元测试
huaqianzkh1 天前
WinForm C#:循环修改控件UI闪烁卡顿?SuspendLayout / ResumeLayout 与 BeginUpdate 优化
开发语言·ui·c#