作者:xianghuanghaibo | 来源:互联网 | 2023-09-10 11:18
-
lable
:字符标签,可自定义文字
也可以显示图片或动图
-
line edit
:单行的输入标签,运行后可输入文字
-
horizontal layout:水平对齐,可将想要水平对齐的控件放入里面就会对齐
-
widget:相当一一个文本框一样的东西 ,可以把控件放到里面,然后这这个widget框整体进行水平布局等操作
- 这只文本框的大小:sizePolicy默认为perferred,变小可设置为fixed
-
Tool Button:可以添加图片,按钮大小根据图片大小按比例缩放
- 插入图片:icon
- toolbuttonstyle:ToolButtonTextBesidelcon让图片和文字一起左右显示
- autoRaise:让按钮的边框透明隐藏
-
radio Button:单选按钮
按钮的objectName为MButton
ui->MButton->setChecked(true);
选中后打印信息
connect(ui->wbutton,&QRadioButton::clicked,[&#61;](){qDebug() <<"选中女";
});
&#43; Group Box&#xff1a;分组&#xff0c;可以把想放到一个组里的按钮放在这个框里
connect(ui->abox,&QCheckBox::stateChanged,[&#61;](int state){qDebug() <<state;});
当你重复的选中和退选的时候&#xff0c;选中后控制台输出2&#xff0c;退选控制台输出0
- list widget&#xff1a;列个表框&#xff0c;可以一行一行的显示文字
需要添加#include
头文件
QListWidgetItem * item &#61; new QListWidgetItem("不仅狂澜走沧海");QListWidgetItem * item2 &#61; new QListWidgetItem("一拳天与压潮头");ui->listWidget->addItem(item);ui->listWidget->addItem(item2);
可以将文字水平居中
QListWidgetItem * item &#61; new QListWidgetItem("不仅狂澜走沧海");QListWidgetItem * item2 &#61; new QListWidgetItem("一拳天与压潮头");ui->listWidget->addItem(item);ui->listWidget->addItem(item2);item->setTextAlignment(Qt::AlignHCenter);
第二种方法
QStringList list;list << "横空出世" << "莽昆仑" << "阅尽人间春色";ui->listWidget->addItems(list);
ui->treeWidget->setHeaderLabels(QStringList()<<"科目" <<"成绩");
ui->treeWidget->setHeaderLabels(QStringList()<<"科目" <<"成绩");QTreeWidgetItem * lit &#61; new QTreeWidgetItem(QStringList()<<"奔波霸");QTreeWidgetItem * lit2 &#61; new QTreeWidgetItem(QStringList()<<"霸波奔");ui->treeWidget->addTopLevelItem(lit);ui->treeWidget->addTopLevelItem(lit2);
ui->treeWidget->setHeaderLabels(QStringList()<<"科目" <<"成绩");QTreeWidgetItem * lit &#61; new QTreeWidgetItem(QStringList()<<"奔波霸");QTreeWidgetItem * lit2 &#61; new QTreeWidgetItem(QStringList()<<"霸波奔");ui->treeWidget->addTopLevelItem(lit);ui->treeWidget->addTopLevelItem(lit2);QStringList heh;heh <<"数学"<<"89";QTreeWidgetItem * aa &#61; new QTreeWidgetItem(heh);lit->addChild(aa);QStringList heh2;heh2 <<"数学"<<"77";QTreeWidgetItem * bb &#61; new QTreeWidgetItem(heh2);lit2->addChild(bb);
ui->table->setColumnCount(3); ui->table->setHorizontalHeaderLabels(QStringList()<<"姓名"<<"性别"<<"年龄");
ui->table->setColumnCount(3); ui->table->setHorizontalHeaderLabels(QStringList()<<"姓名"<<"性别"<<"年龄");ui->table->setRowCount(2);ui->table->setItem(0,0,new QTableWidgetItem("奔波霸"));
QStringList name;name <<"奔波霸" <<"霸波奔";QList<QString> gander;gander << "男"<< "男";for(int i&#61;0;i<2;i&#43;&#43;){int col &#61; 0;ui->table->setItem(i,col&#43;&#43;,new QTableWidgetItem(name[i]));ui->table->setItem(i,col&#43;&#43;,new QTableWidgetItem(gander.at(i)));ui->table->setItem(i,col&#43;&#43;,new QTableWidgetItem(QString::number(i&#43;18)));
在实际运行过程中并没有这箭头&#xff0c;需要自己在添加按钮&#xff0c;通过槽函数连接
ui->stackedWidget->setCurrentIndex(1);connect(ui->page1,&QPushButton::clicked,[&#61;](){ui->stackedWidget->setCurrentIndex(0);});connect(ui->page2,&QPushButton::clicked,[&#61;](){ui->stackedWidget->setCurrentIndex(1);});connect(ui->page3,&QPushButton::clicked,[&#61;](){ui->stackedWidget->setCurrentIndex(2);});
需要添加头文件&#xff1a;#include
ui->comboBox->addItem("自行车");ui->comboBox->addItem("摩托车");ui->comboBox->addItem("拖拉机");connect(ui->tuolaji,&QPushButton::clicked,[&#61;](){ui->comboBox->setCurrentIndex(2);});