当前位置:网站首页>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
边栏推荐
- [performance pressure test] how to do a good job of performance pressure test?
- 快速使用 Jacoco 代码覆盖率统计
- buuctf misc USB
- [CV] Wu Enda machine learning course notes | Chapter 8
- nacos
- [2022 actf] Web Topic recurrence
- pytorch 参数初始化
- [UVM foundation] what is transaction
- Ansible
- Technology cloud report: from robot to Cobot, human-computer integration is creating an era
猜你喜欢
Cnopendata American Golden Globe Award winning data
2022年全国最新消防设施操作员(初级消防设施操作员)模拟题及答案
Qt学习27 应用程序中的主窗口
这5个摸鱼神器太火了!程序员:知道了快删!
JSON data flattening pd json_ normalize
Problem solving: unable to connect to redis
misc ez_ usb
Kbu1510-asemi power supply special 15A rectifier bridge kbu1510
json 数据展平pd.json_normalize
Codeforces Global Round 19
随机推荐
CentOS7下安装PostgreSQL11数据库
Detailed explanation of Kalman filter for motion state estimation
Linux server development, redis source code storage principle and data model
Ansible
Use and analysis of dot function in numpy
[UVM foundation] what is transaction
PHP exports millions of data
Leetcode 43 String multiplication (2022.02.12)
Linux server development, MySQL index principle and optimization
pytest+allure+jenkins環境--填坑完畢
芯片 設計資料下載
Regular e-commerce problems part1
Rust versus go (which is my preferred language?)
Solution: could not find kf5 (missing: coreaddons dbusaddons doctools xmlgui)
The principle and implementation of buffer playback of large video files
IO stream file
Common validation comments
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
Pytest+allure+jenkins installation problem: pytest: error: unrecognized arguments: --alluredir
padavan手动安装php