当前位置:网站首页>QT之一个UI里边多界面切换
QT之一个UI里边多界面切换
2022-06-26 07:41:00 【明月醉窗台】
QT之多界面交换
环境:VS2019+QT_tools
从网上查看了许多大神的帖子,先将多界面切换的方法总结如下:
1.可以通过QT Designer中添加Containers控件里的Stacked Widget实现同一个UI里的页面切换,可以通过鼠标右键或者代码实现增减页操作
2.可以通过建立多个UI文件,然后设置选择其中一个显示,其他隐藏实现不同UI界面的切换,这种方法csdn上帖子很多,在此就不赘述。
3.还有一一种方法就是将以上两种方法结合起来,同时在主窗口插入Stacked Widget,以及建立多个UI文件,再将UI文件作为空间添加到主窗口的Stacked Widget中,实现同一个窗口中的界面切换,这种方法好处是可以实现不同UI编辑的同时不会过于混乱,效率较高。
1.主窗口插入Stacked Widget
VS中找到你的主窗口Ui文件,双击打开进入Designer
完成后选择上方的窗体->查看代码->保存->关闭
//调用举例如下:
ui.stackedWidget->addWidget(A);
ui.stackedWidget->addWidget(B);
2.创新多个Ui文件
右键项目,添加新建项
Ui属性选择QWidget
创建成功后解决方案中会多出3个文件:.cpp、 .h、 .ui
3.多界面切换
主窗口.h
#pragma once
#include <QtWidgets/QMainWindow>
#include"calibration.h"//建立的两个新UI
#include"camerror.h"
#include "ui_Cameraparameter.h"
class Cameraparameter : public QMainWindow
{
Q_OBJECT
public:
Cameraparameter(QWidget *parent = nullptr);
~Cameraparameter();
private:
Ui::CameraparameterClass ui;
calibration* ui_cal;
camerror* ui_error;
private slots:
void on_pushButton_clicked();
void on_pushButton_2_clicked();
};
主窗口.cpp
#include "Cameraparameter.h"
Cameraparameter::Cameraparameter(QWidget *parent)
: QMainWindow(parent)
{
ui.setupUi(this);
//申请两个新界面
ui_cal = new calibration;
ui_error = new camerror;
//将界面添加到stackedWidget控件
ui.stackedWidget->addWidget(ui_cal);
ui.stackedWidget->addWidget(ui_error);
}
Cameraparameter::~Cameraparameter()
{
}
void Cameraparameter::on_pushButton_clicked()
{
ui.stackedWidget->setCurrentIndex(2);
}
void Cameraparameter::on_pushButton_2_clicked()
{
ui.stackedWidget->setCurrentIndex(3);
}
效果展示:
边栏推荐
- 解决 psycopg2.NotSupportedError: PQconninfo not available in libpq < 9.3
- My colleague asked a question I never thought about. Why did kubernetes' superfluous' launch the static pod concept?
- Exit of shell internal value command
- You can command Siri without making a sound! The Chinese team of Cornell University developed the silent language recognition necklace. Chinese and English are OK
- Yyds dry inventory Druid connection pool usage
- QPS
- [UVM basics] TLM common data receiving and sending and data receiving examples
- Yyds dry inventory kubernetes easy service discovery and load balancing (11)
- [UVM practice] Chapter 2: a simple UVM verification platform (4) the ultimate masterpiece of UVM: sequence
- 个人用指南针软件买股票安全吗?怎么炒股买股票呢
猜你喜欢
Redis series - redis startup, client day1-2
5,10,15,20-tetraphenylporphyrin (TPP) and metal complexes fetpp/mntpp/cutpp/zntpp/nitpp/cotpp/pttpp/pdtpp/cdtpp supplied by Qiyue
The first multi platform webcast of 2021ccf award ceremony pays tribute to the winners! CCF outstanding engineer
OSPF design principles, commands take H3C as an example
记一次开发 pgadmin 时执行 Building the Web Assets 遇到的依赖安装问题
Google Earth Engine(GEE) 02-基本了解和学习资源
I3wm get window class
Take you three minutes to get started typescript
Dark red crystal meso-5,10,15,20-tetra (p-aminophenyl) cobalt porphyrin (co TAPP); Meso-5,10,15,20-tetra (p-aminophenyl) cobalt porphyrin no complex (TAPP co no) supplied by Qiyue
How can I find the completely deleted photos in Apple mobile phone?
随机推荐
数据中心灾难恢复的重要参考指标:RTO和RPO
信息学奥赛一本通 1355:字符串匹配问题(strs)
少年,你可知 Kotlin 协程最初的样子?
The first multi platform webcast of 2021ccf award ceremony pays tribute to the winners! CCF outstanding engineer
Yyds dry inventory executor package (executor function)
Tetradecanoxy tetraphenylporphyrin methacrylate mm-tpp-14c; Cetanoxy tetraphenyl porphyrin methacrylate mm-tpp-16c; Purple solid; Qiyue supply
Crosslinked porphyrin based polyimide ppbpi-2, ppbpi-1-cr and ppbpi-2-cr; Porous porphyrin based hyperbranched polyimide (ppbpi-1, ppbpi-2) supplied by Qiyue
Jemter stress test - visualization tool support - [installation]
ES cluster_ block_ exception read_ only_ allow_ Delete question
The difference between insert ignore and insert into
How to quickly merge multiple PDF files?
Children play games (greed, prefix and) - Niuke winter vacation training camp
The long path of Xiao Sha (graph theory, Euler diagram)
职场“大冤种”,不仅身累,心也被掏空……
Redis(4)----浅谈整数集合
C implementation adds a progress bar display effect to the specified column of the GridView table in devaxpress - code implementation method
I3wm get window class
What is the difference between bone conduction earphones and ordinary earphones? Advantages of bone conduction earphones
Yyds dry inventory kubernetes easy service discovery and load balancing (11)
1010. song backtracking with total duration divisible by 60