企业营销型网站seo推广,做一个微信小程序商城需要多少钱,eclipse做网站代码,网站建设相关资料QHBoxLayout水平布局,QVBoxLayout垂直布局,QFormLayout表单布局管理器,是常用的布局管理器,是用代码编写应用界面必不可少的功能类. 1.tips
这里值得注意的是,2个单选按钮(QRadioButton)同时放进一个水平布局管理器(QHBoxLayout)中,相当于放进了一个分组器中,此时,2个单选按钮… QHBoxLayout水平布局,QVBoxLayout垂直布局,QFormLayout表单布局管理器,是常用的布局管理器,是用代码编写应用界面必不可少的功能类. 1.tips
这里值得注意的是,2个单选按钮(QRadioButton)同时放进一个水平布局管理器(QHBoxLayout)中,相当于放进了一个分组器中,此时,2个单选按钮只能同时选中一个.水平布局管理器,顾名思义:放在这个水平布局管理器中的3个控件,只能均匀的排列成一行.代码如下 //添加到水平布局管理器QHBoxLayout* sexLayout new QHBoxLayout;//添加部件,这里把2个单选按钮男女,一起放到了布局管理器中(相当于分组框),此时只能选中一个sexLayout-addWidget(sexLabel); //标签sexLayout-addWidget(manBtn); //单选按钮sexLayout-addWidget(womenBtn); //单选按钮 2.tips
把标签和行编辑器联系起来,建立伙伴关系.使用函数setBuddy()使2者连接起来,达到使用快捷键定位到该行编辑器进行输入.详细看如下代码.
3.tips
不通过设计模式布局界面,而是使用代码把控件,标签,行编辑器等,进行桌面布局.
#include codelayout.h
#include QApplication
#include QLabel
#include QLineEdit
#include QFormLayout
#include QRadioButton
#include QPushButton
#include QSpacerItem//空格项,分隔控件与控件的距离.//使用代码进行构建,不使用设计模式进行设计
int main(int argc, char *argv[])
{QApplication a(argc, argv);CodeLayout w;//标签名QLabel* nameLabel new QLabel(姓名:(N));QLabel* ageLabel new QLabel(年龄:(A));QLabel* emailLabel new QLabel(邮箱:(E));QLabel* numLabel new QLabel(门牌号码:);//文本输入框,文本编辑器QLineEdit* nameLineEdit new QLineEdit;QLineEdit* ageLineEdit new QLineEdit;QLineEdit* emailLineEdit new QLineEdit;QLineEdit* numLineEdit new QLineEdit;//设置伙伴关系nameLabel-setBuddy(nameLineEdit);ageLabel-setBuddy(ageLineEdit);emailLabel-setBuddy(emailLineEdit);//常用于表单,标签布局(水平),布局管理器...前面放标签lable,后面反行编辑器editQFormLayout* headerLayout new QFormLayout;//new 一个对象. QFormLayout(w)指定w为父窗体headerLayout-addRow(nameLabel,nameLineEdit);headerLayout-addRow(ageLabel,ageLineEdit);headerLayout-addRow(emailLabel,emailLineEdit);headerLayout-addRow(numLabel,numLineEdit);QLabel* sexLabel new QLabel(性别:);QRadioButton* manBtn new QRadioButton;QRadioButton* womenBtn new QRadioButton;manBtn-setText(男);womenBtn-setText(女);//添加到水平布局管理器QHBoxLayout* sexLayout new QHBoxLayout;//添加部件,这里把2个单选按钮男女,一起放到了布局管理器中(相当于分组框),此时只能选中一个sexLayout-addWidget(sexLabel);sexLayout-addWidget(manBtn);sexLayout-addWidget(womenBtn);//空格项.分隔控件与控件的距离.提供空白空间使其不紧挨一起QSpacerItem* spacer new QSpacerItem(30,30);QPushButton* okBtn new QPushButton(确定);QHBoxLayout* spacerLayout new QHBoxLayout;//使确定按钮左右缩短一点spacerLayout-addItem(spacer);spacerLayout-addWidget(okBtn);spacerLayout-addItem(spacer);//垂直布局管理器.主布局管理器.QVBoxLayout* mainLayout new QVBoxLayout(w);//指定w为父窗体mainLayout-addLayout(headerLayout);mainLayout-addLayout(sexLayout);mainLayout-addItem(spacer); //添加空隙对象//mainLayout-addWidget(okBtn); //添加部件mainLayout-addLayout(spacerLayout);//添加确定部件按钮mainLayout-setMargin(10); //与窗体的间隙mainLayout-setSpacing(10); //控件间的间隙//设置窗体布局w.setLayout(mainLayout);w.show();return a.exec();
}