当前位置:网站首页>QT learning 25 layout manager (4)
QT learning 25 layout manager (4)
2022-07-03 13:58:00 【A little black sauce】
Qt Study 25 Layout manager ( Four )
The most special layout manager
- Trestle layout manager ( QStackedLayout )
- All components in Perpendicular to the screen Managed in the direction of
- Every time There's only one component It will be displayed on the screen
- Only The topmost component Will be finally displayed

- Characteristics of the trestle layout manager
- Consistent component size And fill the display area of the parent component
- Cannot nest directly Other layout managers
- can Free to switch Components to be displayed
- Can and can only Show a component
- QStackedLayout Usage Summary of
int addWidget(QWidget* widget)QWidget* currentWidget()void setCurrentIndex(int index)int currentIndex()
Programming experiment - Discussion on trestle layout
#ifndef WIDGET_H
#define WIDGET_H
#include <QWidget>
#include <QPushButton>
class Widget : public QWidget
{
Q_OBJECT
private:
QPushButton TestBtn1;
QPushButton TestBtn2;
QPushButton TestBtn3;
QPushButton TestBtn4;
void initBtn();
void initControl();
public:
Widget(QWidget *parent = 0);
~Widget();
};
#endif // WIDGET_H
#include "Widget.h"
#include <QStackedLayout>
#include <QHBoxLayout>
Widget::Widget(QWidget *parent) : QWidget(parent),
TestBtn1(this), TestBtn4(this)
{
initBtn();
initControl();
}
Widget::~Widget()
{
}
void Widget::initBtn()
{
TestBtn1.setText("1st Button");
TestBtn2.setText("2rd Button");
TestBtn3.setText("3th Button");
TestBtn4.setText("Test Button 4: D.T.Software");
}
void Widget::initControl()
{
// Trestle layout manager
QStackedLayout* sLayout = new QStackedLayout();
sLayout->addWidget(&TestBtn1);
// Because the trestle layout manager cannot directly nest other layout managers , So use QWidget Make the middle layer
QWidget* w = new QWidget();
// stay QWidget Set the horizontal layout manager in
QHBoxLayout* hLayout = new QHBoxLayout();
hLayout->addWidget(&TestBtn2);
hLayout->addWidget(&TestBtn3);
w->setLayout(hLayout);
// And then QWidget Add to the trestle layout manager , Play the effect of indirectly nesting the horizontal layout manager
sLayout->addWidget(w);
sLayout->addWidget(&TestBtn4);
sLayout->setCurrentIndex(2); //0:Btn1, 1:Btn2、Btn3, 2:Btn4
setLayout(sLayout);
}
#include "Widget.h"
#include <QApplication>
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
Widget w;
w.show();
return a.exec();
}
The concept of timer
- The timer is In engineering development A very important role
- Timer for Every certain event triggers a message
- timer news It will eventually be transformed into Function call
- On the macro
- The timer will call the specified function at each event interval
Qt The timer in
timer ( QTimer ) How to use
1. Write timer message processing function
2. Create a timer object in the program
3. Connect timer message and message processing function
4. Set the timer interval and start timing
Programming experiment - Use of timer
The new content :
#ifndef WIDGET_H
#define WIDGET_H
class Widget : public QWidget
{
private slots:
void timerTimeout();
};
#endif // WIDGET_H
#include <QTimer>
void Widget::initControl()
{
// The content of the last experiment
// Timer add content
QTimer* timer = new QTimer(this);
connect(timer, SIGNAL(timeout()), this, SLOT(timerTimeout()));
timer->start(2000);
}
void Widget::timerTimeout()
{
// layout() Get the layout manager of the current window
QStackedLayout* sLayout = dynamic_cast<QStackedLayout*>(layout());
if (sLayout != NULL) {
int index = (sLayout->currentIndex()+1) % sLayout->count();
sLayout->setCurrentIndex(index);
}
}
Summary
- QStackedLayout Manage interface components in a stack
- QStackedLayout Components in At most, there is only one display
- QStackedLayout Sure Free to switch Components to be displayed
- QTimer yes Qt Timer component in
- QTimer The message can be triggered at a specified time interval
边栏推荐
- Similarities and differences of sessionstorage, localstorage and cookies
- Folic acid modified metal organic framework (zif-8) baicalin loaded metal organic framework composite magnetic material (AU- [email
- Static linked list (subscript of array instead of pointer)
- 3D视觉——2.人体姿态估计(Pose Estimation)入门——OpenPose含安装、编译、使用(单帧、实时视频)
- Leetcode-1175. Prime Arrangements
- Implementation of Muduo accept connection, disconnection and sending data
- Failure of vector insertion element iterator in STL
- Summary of common error reporting problems and positioning methods of thrift
- [556. Next larger element III]
- Thrift threadmanager and three monitors
猜你喜欢

【BW16 应用篇】安信可BW16模组与开发板更新固件烧录说明

NFT新的契机,多媒体NFT聚合平台OKALEIDO即将上线

Qt学习25 布局管理器(四)

SQL Injection (POST/Select)

Unable to stop it, domestic chips have made another breakthrough, and some links have reached 4nm

Students who do not understand the code can also send their own token, which is easy to learn BSC
[email protected] Nanoparticles) | nano metal organic framework carry"/>Metal organic framework material zif-8 containing curcumin( [email protected] Nanoparticles) | nano metal organic framework carry

Go language web development series 27: Gin framework: using gin swagger to implement interface documents

jvm-运行时数据区

Qt学习24 布局管理器(三)
随机推荐
Stack application (balancer)
太阳底下无新事,元宇宙能否更上层楼?
SQL Injection (AJAX/JSON/jQuery)
Uniapp tips - scrolling components
Go language web development series 27: Gin framework: using gin swagger to implement interface documents
Qt学习21 Qt 中的标准对话框(下)
Golang — template
Summary of common error reporting problems and positioning methods of thrift
Thrift threadmanager and three monitors
PhpMyAdmin stage file contains analysis traceability
jvm-类加载
Multi person collaborative data annotation based on Baidu brain easydata from scratch
The latest BSC can pay dividends. Any B usdt Shib eth dividend destruction marketing can
GoLand 2021.1: rename the go project
HALCON联合C#检测表面缺陷——HALCON例程autobahn
RichView TRVStyle ListStyle 列表样式(项目符号编号)
3D vision - 2 Introduction to pose estimation - openpose includes installation, compilation and use (single frame, real-time video)
Another industry has been broken by Chinese chips. No wonder the leading analog chip companies in the United States have cut prices and sold off
Qt学习19 Qt 中的标准对话框(上)
logback日志的整理