当前位置:网站首页>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
边栏推荐
- Tianshu night reading notes -- disassembly engine xde32
- 你知道你的ABC吗(春季每日一题 1)
- DDD概念复杂难懂,实际落地如何设计代码实现模型?
- Transformers 库的基本使用
- Fan benefits, JVM manual (including PDF)
- Abnova CSV magnetic beads description in Chinese and English
- 放养但没有完全放养(春季每日一题 2)
- Half of the year has passed. How many flags have been achieved at the end of the year?
- Poj3669 meteor shower (BFS pretreatment)
- Unity C# 网络学习(六)——FTP(二)
猜你喜欢

2个NPN三极管组成的恒流电路

多模态数据也能进行MAE?伯克利&谷歌提出M3AE,在图像和文本数据上进行MAE!最优掩蔽率可达75%,显著高于BERT的15%

Fan benefits, JVM manual (including PDF)

JVM directive

Abnova丨BSG 单克隆抗体中英文说明

【LeetCode】11、盛最多水的容器

leetcode:2104. Subarray range and

动手学数据分析 数据建模和模型评估

(CVPR 2020) Learning Object Bounding Boxes for 3D Instance Segmentation on Point Clouds

Day 04 - file IO
随机推荐
Is CICC securities reliable? Is it safe to open a securities account?
O (log (min (m, n))
谷歌浏览器控制台 f12怎么设置成中文/英文 切换方法,一定要看到最后!!!
‘distutils‘ has no attribute ‘version
JVM directive
Status quo analysis: how "one cloud and multi-core" can promote the rapid deployment of information innovation projects
mpls 笔记 part 1
Abnova a4gnt polyclonal antibody
linux上查看mysql的密码_Linux下MySQL忘记密码「建议收藏」
‘distutils‘ has no attribute ‘version
void* 指针
屡获大奖的界面控件开发包DevExpress v22.1官宣发布
TSDB在民机行业中的应用
Full arrangement ii[duplicate removal of the same elements + standard backtracking]
Tianshu night reading notes -- memory paging mechanism
lnmp环境安装ffmpeg,并在Yii2中使用
泰山OFFICE技术讲座:竖排时中文标点的简单研究
明日考试 最后一天如何备考?二造考点攻略全整理
Search two-dimensional matrix [clever use of bisection + record solution different from inserting bisection]
AutoCAD - two extension modes