qt布局控件叠在一起_Qt基本控件及三大布局

本文详细介绍了Qt中的基本控件,包括QHBoxLayout、QVBoxLayout和QGridLayout三大布局,以及label、pushbutton、radiobutton等常见控件的使用。此外,还探讨了Qt的信号槽机制,通过实例展示了如何连接和触发控件信号。最后,通过不同布局类型的示例,展示了如何在实际应用中组合和管理这些控件。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

Qt基本控件及三大布局

来源: http://blog.youkuaiyun.com/a2604539133/article/details/73920696

Qt基本模块

一、Qt的三大布局

QHBoxLayout:

水平显示布局,所有在其上面摆放的控件只能水平排列下去;

QVBoxLayout:

垂直显示布局,所有在其上面摆放的控件只能垂直排列下去;

QGridLayout

格子显示布局,可以按照表格的形式显示布局;

二、Qt的控件

label:标签,可以显示文本信息,只读;

pushbutton : 普通按钮;

radiobutton : 单选按钮,多个单选按钮中只能选择一个,但是必须放入groupbox中,类似单选题;

checkbox : 多选复选按钮,可以选择同时选择多个,类似多选题;

lineedit : 单行文本编辑框,可以输入单行文本;

textedit : 多行文本输入框,可以输入显示多行文本和图片;

combobox : 下拉文本输入框,在输入框的最右边有个三角下拉按钮,可以选择输入,也可以手动输入;

textbrower : 多行文本显示框,只读;

groupbox : 可以在里面放入特点的东西,统一管理;

slider : 模拟显示滑动条;

spinbox : 数值显示滑动条;

dateedit :

timeedit :

datetimeedit :

lcdnumber :

三、Qt的信号槽

在Qt中所有的对象(继承QObject类)都有connect函数,只要有这个函数就能建立信号槽(通过触发某个控件的信号函数,执行槽中相应的函数);(暂时这样理解,还是有点理解不全面的,之后学习到再来修改);

在Qt中信号槽中可以使用自带的函数,四个参数;也可以执行自定义的函数,三个参数;具体看下面test4的例子就明白了。

#include

#include

#include

#include

#include

#include

#include

#include

#include

#include

#include

#include

#include

#include

#include

#include

#include

#include

#include

#include

#include "MyWidgetEvent.h"

void test() ;

int main(int argc, char *argv[]) {

QApplication a(argc, argv);

test() ;

return a.exec();

}

void test(){

}

void test5ManyKongJian() {

QWidget *nanWidget = new QWidget() ;

QVBoxLayout *nanVLayout = new QVBoxLayout() ;

/*

**测试label控件

*/

QLabel *label=nullptr ;

nanVLayout->addWidget( label = new QLabel("baidu") ) ;

//QPixmap me("./me.png") ;

//label->setPixmap( me ) ;//问题:链接和图片重复了,怎么分开

label->setWordWrap( true ) ;

label->adjustSize() ;

nanVLayout->connect( label , &QLabel::linkActivated , []( QString str){

qDebug()<

} ) ;

/*

**测试lineedit控件

*/

QLineEdit *lineEdit ;

nanVLayout->addWidget( lineEdit = new QLineEdit("hello") ) ;

/*

**测试button控件

*/

QPushButton *button ;

nanVLayout->addWidget( button = new QPushButton("???") ) ;

button->setStyleSheet("QPushButton {font:bold 16px; color:red;padding:5px}") ;

nanWidget->connect( button , &QPushButton::clicked , [](bool flag){

qDebug()<< "button" ;

}) ;

/*

**测试radiobutton控件

*/

QRadioButton *radioButton ;

nanVLayout->addWidget( radioButton = new QRadioButton("qradiobutton") ) ;

radioButton->setStyleSheet("QRadioButton {font:bold 16px;color:blue;padding:5px}") ;

rad

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值