当前位置:网站首页>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
边栏推荐
- Go language unit test 5: go language uses go sqlmock and Gorm to do database query mock
- JVM family - overview, program counter day1-1
- 金属有机骨架MIL-88负载阿霉素DOX|叶酸修饰UiO-66-NH2负载阿霉素[email protected]纳米粒子
- Halcon combined with C # to detect surface defects -- Halcon routine autobahn
- [how to earn a million passive income]
- Analysis of the characteristics of page owner
- Go language web development series 30: gin: grouping by version for routing
- UiO-66-COOH装载苯达莫司汀|羟基磷灰石( HA) 包裹MIL-53(Fe)纳米粒子|装载黄芩苷锰基金属有机骨架材料
- [développement technologique - 24]: caractéristiques des technologies de communication Internet des objets existantes
- Use vscode to view hex or UTF-8 codes
猜你喜欢
[email protected]纳米粒子"/>金属有机骨架MIL-88负载阿霉素DOX|叶酸修饰UiO-66-NH2负载阿霉素[email protected]纳米粒子

Flutter dynamic | fair 2.5.0 new version features

Go language unit test 3: go language uses gocovey library to do unit test

There is nothing new under the sun. Can the meta universe go higher?

jvm-类加载

小项目(servelt+jsp+mysql+EL+JSTL)完成一个登录功能的Servlet,具有增删改查的操作。实现登录身份验证,防止非法登录,防止多点登录,记住用户名密码功能。

Go language web development series 25: Gin framework: using MD5 to verify the signature for the interface station
![Mysql:insert date:SQL 错误 [1292] [22001]: Data truncation: Incorrect date value:](/img/2f/33504391a661ecb63d42d75acf3a37.png)
Mysql:insert date:SQL 错误 [1292] [22001]: Data truncation: Incorrect date value:

Conversion function and explicit

Implementation of Muduo accept connection, disconnection and sending data
随机推荐
Uniapp skills - scrolling components -1
jvm-类加载
[développement technologique - 24]: caractéristiques des technologies de communication Internet des objets existantes
The latest BSC can pay dividends. Any B usdt Shib eth dividend destruction marketing can
Golang — template
page owner特性浅析
Sequence table (implemented in C language)
Spring cup eight school league
[how to earn a million passive income]
logback日志的整理
[技術發展-24]:現有物聯網通信技術特點
又一个行业被中国芯片打破空白,难怪美国模拟芯片龙头降价抛售了
RocksDB LRUCache
Depth and breadth first traversal of tree (regardless of binary tree)
Multi person collaborative data annotation based on Baidu brain easydata from scratch
[combinatorics] permutation and combination (examples of combinatorial number of multiple sets | three counting models | selection problem | combinatorial problem of multiple sets | nonnegative intege
JS new challenges
3D vision - 2 Introduction to pose estimation - openpose includes installation, compilation and use (single frame, real-time video)
Ocean CMS vulnerability - search php
Field problems in MySQL