【QT】控件的用法介绍

QLabel(很重要)

QPixmap在Qt中代表的就是一张图片

QPicture不是图片

如果图片不能完整显示,那就是没有布局

c 复制代码
   //添加静态图片
       如果构造的时候没有指定,可以在外面用load()指定图片路径
  ui->label->setPixmap(QPixmap(":/picture/86.jpg"));
//使得图片完整显示  
ui->label->setScaledContents(true);

添加动态图片

c 复制代码
 //添加动态图片
       QMovie *movie = new QMovie(":/picture/mario.gif");
       ui->label->setMovie(movie);
       movie->start();//启动播放

只能播放gif的图片

不能播放mp4

必须是指针,因为在看的时候movie,对象变量已经被析构了,就看不到了,而指针则需要手动去释放(这里是Qt的内存回收机制来释放)。

单选框

Group Box

一定要对放进去的控件布局,否则看不到

多选框

加入槽函数

c 复制代码
#include "widget.h"
#include "ui_widget.h"
#include <QMessageBox>
#include <QCheckBox>
Widget::Widget(QWidget *parent) :
    QWidget(parent),
    ui(new Ui::Widget)
{  
       ui->setupUi(this);
       this->setWindowTitle("网易");
       //this->setWindowIcon(QIcon(":/picture/86.jpg"));
       this->setFixedSize(500,500);
              //单选按钮
       connect(ui->radioButton,&QRadioButton::released,this,[=](){

           QMessageBox::information(this,"radiobutton","haha+++");
       });
//多选按钮
       connect(ui->checkBox,&QCheckBox::stateChanged,this,[=](int state){

           QMessageBox::information(this,"checkBox",QString::number(state));
       });                                             //打印state的值

}

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

listWidget

c 复制代码
  ui->listWidget->addItem("你好,世界");
   QListWidgetItem *Item = new  QListWidgetItem(QIcon(":/picture/86.jpg"),"king");
   ui->listWidget->addItem(Item);
   //ui->listWidget->addItem(new QListWidgetItem(QIcon(":/picture/86.jpg"),"king"));

Table Widget

c 复制代码
        //1.指定行数
        ui->tableWidget->setRowCount(100);
        //2.指定列数
        ui->tableWidget->setColumnCount(3);
        
    
        QStringList list;
        list<<"姓名"<<"性别"<<"年龄";
        ui->tableWidget->setHorizontalHeaderLabels(list);
        QTableWidgetItem *Item1 = new QTableWidgetItem(QIcon(":/picture/86.jpg"),"king");
        ui->tableWidget->setItem(0,0,Item1);

滚轮

可以显示更多内容

ToolBox

StackedWidget

c 复制代码
    connect(ui->pushButton_10,&QPushButton::pressed,this,[=](){

        ui->stackedWidget->setCurrentIndex(0);
    });
    connect(ui->pushButton_11,&QPushButton::pressed,this,[=](){

        ui->stackedWidget->setCurrentIndex(1);
    });
    connect(ui->pushButton_8,&QPushButton::pressed,this,[=](){

        ui->stackedWidget->setCurrentIndex(2);
    });

Combo Box

相关推荐
卷到起飞的数分12 分钟前
Java零基础笔记07(Java编程核心:面向对象编程 {类,static关键字})
java·开发语言·笔记
谁他个天昏地暗24 分钟前
Java 实现 Excel 文件对比与数据填充
java·开发语言·excel
kaikaile199540 分钟前
使用Python进行数据可视化的初学者指南
开发语言·python·信息可视化
大P哥阿豪40 分钟前
Go defer(二):从汇编的角度理解延迟调用的实现
开发语言·汇编·后端·golang
前端开发与ui设计的老司机42 分钟前
UI前端与数字孪生融合新领域:智慧环保的污染源监测与治理
前端·ui
意疏1 小时前
【Python篇】PyCharm 安装与基础配置指南
开发语言·python·pycharm
GuokLiu2 小时前
250708-通过两块硬盘拷贝DeepSeek两个满血版模型的bash脚本
开发语言·chrome·bash
钢铁男儿3 小时前
PyQt5高级界而控件(容器:装载更多的控件QDockWidget)
数据库·python·qt
iCxhust8 小时前
c# U盘映像生成工具
开发语言·单片机·c#
yangzhi_emo9 小时前
ES6笔记2
开发语言·前端·javascript