当前位置:网站首页>QT learning 26 integrated example of layout management
QT learning 26 integrated example of layout management
2022-07-07 07:59:00 【A little black sauce】
Qt Study 26 Comprehensive example of layout management
Demand analysis
- Practice developing a wizard user interface
- Show on the same interface Different wizard pages
- adopt “ The previous step ” and “ next step ” Button to switch
- The element components and component layout on different pages are different
- The components in the page are arranged through the layout manager
Solution
- Interface design through layout nesting
- adopt QStackedLayout Manage different pages
- Generate different pages through sub components
Programming experiment - Wizard user interface
#ifndef WIDGET_H
#define WIDGET_H
#include <QWidget>
#include <QStackedLayout>
#include <QPushButton>
#include <QLabel>
#include <QLineEdit>
class Widget : public QWidget
{
Q_OBJECT
private:
QStackedLayout sLayout;
QPushButton preBtn;
QPushButton nextBtn;
QLabel fLabel1;
QLabel fLabel2;
QLabel fLabel3;
QLabel fLabel4;
QLineEdit sEdit;
QPushButton tBtn1;
QPushButton tBtn2;
void initControl();
QWidget* get1stPage();
QWidget* get2ndPage();
QWidget* get3rdPage();
private slots:
void onPreBtnClicked();
void onNextBtnClicked();
public:
Widget(QWidget *parent = 0);
~Widget();
};
#endif // WIDGET_H
#include "Widget.h"
#include <QVBoxLayout>
#include <QHBoxLayout>
#include <QGridLayout>
#include <QFormLayout>
Widget::Widget(QWidget *parent)
: QWidget(parent)
{
initControl();
}
Widget::~Widget()
{
}
void Widget::initControl()
{
QVBoxLayout* vLayout = new QVBoxLayout();
QHBoxLayout* hLayout = new QHBoxLayout();
vLayout->addLayout(&sLayout);
vLayout->addLayout(hLayout);
preBtn.setText("pre page");
preBtn.setMinimumSize(160, 30);
nextBtn.setText("next page");
nextBtn.setMinimumSize(160, 30);
connect(&preBtn, SIGNAL(clicked()), this, SLOT(onPreBtnClicked()));
connect(&nextBtn, SIGNAL(clicked()), this, SLOT(onNextBtnClicked()));
hLayout->addWidget(&preBtn);
hLayout->addWidget(&nextBtn);
sLayout.addWidget(get1stPage());
sLayout.addWidget(get2ndPage());
sLayout.addWidget(get3rdPage());
setLayout(vLayout);
}
QWidget *Widget::get1stPage()
{
QWidget* ret = new QWidget();
QGridLayout* gLayout = new QGridLayout();
fLabel1.setText("This");
fLabel2.setText("is");
fLabel3.setText("1st");
fLabel4.setText("page");
gLayout->addWidget(&fLabel1, 0, 0);
gLayout->addWidget(&fLabel2, 0, 1);
gLayout->addWidget(&fLabel3, 1, 0);
gLayout->addWidget(&fLabel4, 1, 1);
ret->setLayout(gLayout);
return ret;
}
QWidget *Widget::get2ndPage()
{
QWidget* ret = new QWidget();
QFormLayout* fLayout = new QFormLayout();
sEdit.setText("This is 2nd page");
fLayout->addRow("Hint:", &sEdit);
ret->setLayout(fLayout);
return ret;
}
QWidget *Widget::get3rdPage()
{
QWidget* ret = new QWidget();
QVBoxLayout* vLayout = new QVBoxLayout();
tBtn1.setText("This is");
tBtn2.setText("3rd page");
vLayout->addWidget(&tBtn1);
vLayout->addWidget(&tBtn2);
ret->setLayout(vLayout);
return ret;
}
void Widget::onPreBtnClicked()
{
int index = ((sLayout.currentIndex() - 1) + 3) % 3;
sLayout.setCurrentIndex(index);
}
void Widget::onNextBtnClicked()
{
int index = (sLayout.currentIndex() + 1) % 3;
sLayout.setCurrentIndex(index);
}
#include "Widget.h"
#include <QApplication>
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
Widget w;
w.show();
return a.exec();
}
matters needing attention
- Container of any component You can specify the layout manager
- Components in the same layout manager have the same parent component
- While setting layout management Implicit designated parent-child relationship
- In the figure Components 1 and Components 2 Managed by the same layout manager , Have the same parent component .
Summary
- The layout manager can Nested with each other to form a complex user interface
- Any container component can set the layout manager
- Components in the same layout manager have the same parent component
- The parent-child relationship between components is Qt An important way of memory management in
边栏推荐
- Linux server development, MySQL cache strategy
- Solution: could not find kf5 (missing: coreaddons dbusaddons doctools xmlgui)
- [VHDL parallel statement execution]
- [UTCTF2020]file header
- [performance pressure test] how to do a good job of performance pressure test?
- [Stanford Jiwang cs144 project] lab4: tcpconnection
- php导出百万数据
- pytest+allure+jenkins環境--填坑完畢
- Wx is used in wechat applet Showtoast() for interface interaction
- @component(““)
猜你喜欢
【斯坦福计网CS144项目】Lab4: TCPConnection
MySQL multi column index (composite index) features and usage scenarios
[2022 ciscn] replay of preliminary web topics
2022焊工(初级)判断题及在线模拟考试
[Matlab] Simulink 自定义函数中的矩阵乘法工作不正常时可以使用模块库中的矩阵乘法模块代替
2022年全国最新消防设施操作员(初级消防设施操作员)模拟题及答案
These five fishing artifacts are too hot! Programmer: I know, delete it quickly!
Common validation comments
json 数据展平pd.json_normalize
QT learning 28 toolbar in the main window
随机推荐
Few-Shot Learning && Meta Learning:小样本学习原理和Siamese网络结构(一)
Linux server development, MySQL process control statement
Installing postgresql11 database under centos7
Iterable、Collection、List 的常见方法签名以及含义
misc ez_usb
[2022 ciscn] replay of preliminary web topics
SQL优化的魅力!从 30248s 到 0.001s
buuctf misc USB
Padavan manually installs PHP
【VHDL 并行语句执行】
[Stanford Jiwang cs144 project] lab3: tcpsender
2022-07-06: will the following go language codes be panic? A: Meeting; B: No. package main import “C“ func main() { var ch chan struct
Leanote private cloud note building
Téléchargement des données de conception des puces
Live online system source code, using valueanimator to achieve view zoom in and out animation effect
2022 simulated examination question bank and online simulated examination of tea master (primary) examination questions
微信小程序基本组件使用介绍
[GUET-CTF2019]虚假的压缩包
探索干货篇!Apifox 建设思路
[mathematical notes] radian