Qt基本控件及三大布局
来源: http://blog.csdn.net/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