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);
}
相关推荐
swany24 分钟前
同步数据中,只需要几秒钟 & milvus向量数据库不可用 dify1.16.1 升级后踩坑记录
开发语言·python·numpy
小杍随笔26 分钟前
2025年Rust GUI框架实战万字避坑指南
开发语言·后端·rust
geovindu33 分钟前
CSharp: LogHelper
开发语言·后端·c#·.net
奈斯先生Vector41 分钟前
大模型 Agentic Workflow 架构解构:异构 API 调度与 Token 路由的多模态系统设计
开发语言·前端·架构·prompt·aigc·音视频
冻柠檬飞冰走茶44 分钟前
PTA基础编程题目集 7-20 打印九九口诀表(C语言实现)
c语言·开发语言·数据结构·算法
Richard.Wong1 小时前
qt生成dll供C#调用
开发语言·qt
wang_xin_8882 小时前
PHP函数
开发语言·php
Immortal__y2 小时前
php函数
开发语言·php
AI砖家2 小时前
多商户多租户系统架构设计文档(Java版)
java·开发语言·系统架构·多租户·多商户
鱼子星_3 小时前
【C++】深入剖析list:list及其双向迭代器实现
开发语言·数据结构·c++·笔记·stl·list