当前位置:网站首页>Basic layout -qhboxlayout class, qvboxlayout class, qgridlayout class
Basic layout -qhboxlayout class, qvboxlayout class, qgridlayout class
2022-06-25 01:58:00 【Full stack programmer webmaster】
Hello everyone , I meet you again , I'm your friend, Quan Jun .
(1) newly build Qt Widget Application, Project name UserInfo, Base class QDialog, Cancel creating interface ; (2) open dialog.h The header file , Declare the controls in the dialog box in the header file , Add code
#ifndef DIALOG_H
#define DIALOG_H
#include <QDialog>
// Add header file
#include <QLabel>
#include <QLineEdit>
#include <QComboBox>
#include <QTextEdit>
#include <QGridLayout>
class Dialog : public QDialog
{
Q_OBJECT
public:
Dialog(QWidget *parent = 0);
~Dialog();
private:// Add the following code
// left
QLabel *UserNameLabel;
QLabel *NameLabel;
QLabel *SexLabel;
QLabel *DepartmentLabel;
QLabel *AgeLabel;
QLabel *OtherLabel;
QLineEdit *NameLineEdit;
QLineEdit *UserNameLineEdit;
QComboBox *SexComboBox;
QTextEdit *DepartmentTextEdit;
QLineEdit *AgeLineEdit;
QGridLayout *LeftLayout;
// On the right side
QLabel *HeadLabel;// Upper right corner
QLabel *HeadIconLabel;
QPushButton *UpdateHeadBtn;
QHBoxLayout *TopRightLayout;
QLabel *IntroductionLabel;
QTextEdit *IntroductionTextEdit;
QVBoxLayout *RightLayout;
// Bottom
QPushButton *OkBtn;
QPushButton *CancelBtn;
QHBoxLayout *ButtomLayout;
};
#endif // DIALOG_H
(2) open dialog.cpp file , In the class Dialog Add the following code to the constructor of :
#include "dialog.h"
// Add header file
#include <QLabel>
#include <QLineEdit>
#include <QComboBox>
#include <QPushButton>
#include <QFrame>
#include <QGridLayout>
#include <QPixmap>
#include <QHBoxLayout>
Dialog::Dialog(QWidget *parent)
: QDialog(parent)
{
setWindowTitle(tr("UserInfo"));
/*********** left *********/
UserNameLabel=new QLabel(tr(" user name : "));
UserNameLineEdit=new QLineEdit;
NameLabel=new QLabel(tr(" full name :"));
NameLineEdit=new QLineEdit;
SexLabel=new QLabel(tr(" Gender :"));
SexComboBox=new QComboBox;
SexComboBox->addItem(tr(" Woman "));
SexComboBox->addItem(tr(" male "));
DepartmentLabel=new QLabel(tr(" department :"));
DepartmentTextEdit=new QTextEdit;
AgeLabel=new QLabel(tr(" remarks :"));
AgeLineEdit=new QLineEdit;
OtherLabel=new QLabel(tr(" remarks :"));
OtherLabel->setFrameStyle(QFrame::Panel|QFrame::Sunken);
// Set the style of the control ,setFrameStyle() yes QFrame Methods , Parameter with or | To set the panel style of the control , By shape (QFrame::Shape) And shadows (QFrame::shadow) Two cooperative decisions . There are six shapes , Namely NoFrame,Panel,Box,HLine,VLine,WinPanel; There are three kinds of shadows ,Plain,Raised,Sunken.
LeftLayout=new QGridLayout();// Left layout , Because this layout manager is not the main layout manager , So there is no need to specify the parent window
// Add the controls that need layout to the layout
LeftLayout->addWidget(UserNameLabel,0,0);// user name
LeftLayout->addWidget(UserNameLineEdit,0,1);
LeftLayout->addWidget(NameLabel,1,0);// full name
LeftLayout->addWidget(NameLineEdit,1,1);
LeftLayout->addWidget(SexLabel,2,0);// Gender
LeftLayout->addWidget(SexComboBox,2,1);
LeftLayout->addWidget(DepartmentLabel,3,0);// department
LeftLayout->addWidget(DepartmentTextEdit,3,1);
LeftLayout->addWidget(AgeLabel,4,0);// Age
LeftLayout->addWidget(AgeLineEdit,4,1);
LeftLayout->addWidget(OtherLabel,5,0,1,2);// other
LeftLayout->setColumnStretch(0,1);
LeftLayout->setColumnStretch(1,3);
// Set the proportion of space occupied by two columns , This example is set as 1:3, Even if the dialog size changes , The width ratio between the two columns remains unchanged
/********** On the right side ***********/
HeadLabel =new QLabel(tr(" Head portrait :"));// Upper right corner
HeadIconLabel=new QLabel;
QPixmap icon("312.pgn");
HeadIconLabel->setPixmap(icon);
HeadIconLabel->resize(icon.width(),icon.height());
UpdateHeadBtn=new QPushButton(tr(" to update "));
// Complete the layout of the upper right avatar selection area
TopRightLayout=new QHBoxLayout();
TopRightLayout->setSpacing(20);// Set the spacing between controls to 20
TopRightLayout->addWidget(HeadLabel);
TopRightLayout->addWidget(HeadIconLabel);
TopRightLayout->addWidget(UpdateHeadBtn);
IntroductionLabel=new QLabel(tr(" Personal instructions :"));// Lower right corner
IntroductionTextEdit=new QTextEdit;
// Complete the layout on the right
RightLayout=new QVBoxLayout();
RightLayout->setMargin(10);
RightLayout->addLayout(TopRightLayout);
RightLayout->addWidget(IntroductionLabel);
RightLayout->addWidget(IntroductionTextEdit);
/******* Bottom ********/
OkBtn=new QPushButton(tr(" determine "));
CancelBtn=new QPushButton(tr(" Cancel "));
// Complete the layout of the two buttons below
ButtomLayout=new QHBoxLayout();
ButtomLayout->addStretch();
// Insert a placeholder before the button , Align the two buttons to the right , And when the size of the entire dialog box changes , Make sure that the size of the button does not change .
ButtomLayout->addWidget(OkBtn);
ButtomLayout->addWidget(CancelBtn);
/************/
QGridLayout *mainLayout=new QGridLayout(this);
// Realize the main layout , Specify the parent window this, You can also call this->setLayout(mainLayout) Realization
mainLayout->setMargin(15);// Set the margin of the dialog box to 15
mainLayout->setSpacing(10);
mainLayout->addLayout(LeftLayout,0,0);
mainLayout->addLayout(RightLayout,0,1);
mainLayout->addLayout(ButtomLayout,1,0,1,2);
mainLayout->setSizeConstraint(QLayout::SetFixedSize);
// Set optimization explicit , Even if the control presses its sizeHint() The size of is explicit , And the user cannot change the size of the dialog box .
}
Dialog::~Dialog()
{
}
Publisher : Full stack programmer stack length , Reprint please indicate the source :https://javaforall.cn/151802.html Link to the original text :https://javaforall.cn
边栏推荐
- leetcode:2104. Subarray range and
- Do you know your ABC
- Huawei laptop, which grew against the trend in Q1, is leading PC into the era of "smart office"
- Q1季度逆势增长的华为笔电,正引领PC进入“智慧办公”时代
- 现状分析:“一云多芯”如何推动信创项目快速部署
- Chinese and English instructions of Papain
- Elastase instructions in Chinese and English
- MeterSphere开源持续测试平台与阿里云云效DevOps的集成
- Half of the year has passed. How many flags have been achieved at the end of the year?
- Fan benefits, JVM manual (including PDF)
猜你喜欢
"One good programmer is worth five ordinary programmers!"
动手学数据分析 数据建模和模型评估
uni-app集成极光推送插件后真机调试提示“当前运行的基座不包含原生插件[JG-JPush]...”问题的解决办法
Fake wireless speakers in stores? Sony responded: the product has reserved a wired connection interface, which can be used in complex scenarios
JVM directive
海河实验室创新联合体成立 GBASE成为首批创新联合体(信创)成员单位
Integration of metersphere open source continuous testing platform and Alibaba cloud cloud cloud efficient Devops
Fan benefits, JVM manual (including PDF)
Abnova a4gnt polyclonal antibody
js数组对象转对象
随机推荐
Fan benefits, JVM manual (including PDF)
非凸联合创始人李佐凡:将量化作为自己的终身事业
脱氧核糖核酸酶I中英文说明书
Deoxyribonuclease I instructions in Chinese and English
ICML2022 | 用神经控制微分方程建立反事实结果的连续时间模型
sql 聚合函数对 null 的处理[通俗易懂]
国内炒股开户正规安全的具体名单
Preg in PHP_ How to replace variable data
Chrysanthemum chain (winter vacation daily question 39)
MPLS notes Part 1
php中preg_replace如何替换变量数据
RedisTemplate操作Redis,这一篇文章就够了(一)[通俗易懂]
tmux 如何自定义背景颜色 | How does the tmux color palette work?
木瓜蛋白酶中英文说明书
Some Modest Advice for Graduate Students - by Stephen C. Stearns, Ph.D.
Tianshu night reading notes -- disassembly engine xde32
An Chaoyun: "one cloud with multiple cores" supports the implementation of the national information innovation government cloud
Baidu voice synthesizes voice files and displays them on the website
Taishan Office Technology Lecture: a simple study of Chinese punctuation in vertical arrangement
Which account is safer and better for access letter