当前位置:网站首页>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
边栏推荐
- 顺序表(C语言实现)
- The latest BSC can pay dividends. Any B usdt Shib eth dividend destruction marketing can
- 如何使用lxml判断网站公告是否更新
- 【吉林大学】考研初试复试资料分享
- Qt学习20 Qt 中的标准对话框(中)
- pytorch 载入历史模型时更换gpu卡号,map_location设置
- 使用vscode查看Hex或UTF-8编码
- 金属有机骨架(MOFs)抗肿瘤药载体|PCN-223装载甲硝唑|UiO-66包载盐酸环丙沙星([email protected])
- Field problems in MySQL
- MySQL 数据增删改查综合案例
猜你喜欢
金属有机骨架MOFs装载非甾体类抗炎药物|ZIF-8包裹普鲁士蓝负载槲皮素(制备方法)
[email protected]纳米颗粒)|纳米金属有机框架搭载雷帕霉素|科研试剂"/>
金属有机骨架材料ZIF-8包载姜黄素([email protected]纳米颗粒)|纳米金属有机框架搭载雷帕霉素|科研试剂
GoLand 2021.2 configure go (go1.17.6)
28:第三章:开发通行证服务:11:在配置文件中定义属性,然后在代码中去获取;
Qt学习20 Qt 中的标准对话框(中)
Qt学习22 布局管理器(一)
[email protected]纳米粒子"/>
金属有机骨架MIL-88负载阿霉素DOX|叶酸修饰UiO-66-NH2负载阿霉素[email protected]纳米粒子
The latest BSC can pay dividends. Any B usdt Shib eth dividend destruction marketing can
Dlopen() implements dynamic loading of third-party libraries
Qt学习23 布局管理器(二)
随机推荐
金属有机骨架(MOFs)抗肿瘤药载体|PCN-223装载甲硝唑|UiO-66包载盐酸环丙沙星([email protected])
Cross linked cyclodextrin metal organic framework loaded methotrexate slow-release particles | metal organic porous material uio-66 loaded with flavonoid glycosides | Qiyue
PhpMyAdmin stage file contains analysis traceability
Qt学习22 布局管理器(一)
Golang - command line tool Cobra
RichView TRVStyle ListStyle 列表样式(项目符号编号)
如何使用lxml判断网站公告是否更新
NFT新的契机,多媒体NFT聚合平台OKALEIDO即将上线
消息订阅与发布
Use vscode to view hex or UTF-8 codes
Halcon combined with C # to detect surface defects -- Halcon routine autobahn
[bw16 application] instructions for firmware burning of Anxin Ke bw16 module and development board update
Go language unit test 5: go language uses go sqlmock and Gorm to do database query mock
项目协作的进度如何推进| 社区征文
Spring cup eight school league
Go language web development series 28: solve cross domain access of CORS with gin contrib / CORS
Qt学习24 布局管理器(三)
JS general form submission 1-onsubmit
Mastering the cypress command line options is the basis for truly mastering cypress
Summary of common error reporting problems and positioning methods of thrift