当前位置:网站首页>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);
}
效果展示:
边栏推荐
- Quickly find five channels for high-quality objects, quickly collect and avoid detours
- Alkynyl crosslinked porphyrin based polyimide materials (ppbpi-h-cr, ppbpi Mn cr.ppbpi Fe Cr); Metalloporphyrin based polyimide (ppbpi Mn, ppbpi FE) supplied by Qiyue
- Yyds dry inventory kubernetes easy service discovery and load balancing (11)
- 指南针炒股软件开户是合法的吗?安全吗
- JMeter stress test web agent local interface test [teaching]
- Jmeter压力测试-Web代理本地接口测试【教学篇】
- Apache InLong毕业成为顶级项目,具备百万亿级数据流处理能力!
- Which of the top ten securities companies has the lowest commission fee and is the most safe and reliable?
- ECE 9203/9023 analysis
- The difference between insert ignore and insert into
猜你喜欢

What are the characteristics of digital factory in construction industry

记一次开发 pgadmin 时执行 Building the Web Assets 遇到的依赖安装问题

Liujinhai, chief architect of zhongang Mining: according to the analysis of fluorite supply and demand, it is estimated that the fluorine coating market has great potential

The first multi platform webcast of 2021ccf award ceremony pays tribute to the winners! CCF outstanding engineer
![5,10,15,20-tetra (4-methoxycarbonylphenyl) porphyrin tcmpp purple crystal; Meso-5,10,15,20-tetra (4-methoxyphenyl) porphyrin tmopp|zn[t (4-mop) p] and co[t (4-mop) p] complexes](/img/51/136eda75986fc01282558e626b2faf.jpg)
5,10,15,20-tetra (4-methoxycarbonylphenyl) porphyrin tcmpp purple crystal; Meso-5,10,15,20-tetra (4-methoxyphenyl) porphyrin tmopp|zn[t (4-mop) p] and co[t (4-mop) p] complexes

Iron / zinc / copper / platinum metal complexes such as 5,10,15,20-tetra (4-hydroxyphenyl) porphyrin (THPP) / (thppfe) / (thppzn) / (thppcu) / (thpppt) - Qiyue R & D

Google Earth Engine(GEE) 01-中输入提示快捷键Ctrl+space无法使用的问题

Redis(5)----浅谈压缩列表

Kalman filter_ Recursive Processing

少年,你可知 Kotlin 协程最初的样子?
随机推荐
3D porphyrin MOF (mof-p5) / 3D porphyrin MOF (mof-p4) / 2D cobalt porphyrin MOF (ppf-1-co) / 2D porphyrin COF (POR COF) / supplied by Qiyue
The performance of iron and steel enterprises was expected to be good in January this year. Since February, the prices of products of iron and steel enterprises have increased significantly. A mighty
一文搞懂Glide,不懂来打我
Here is the command to display the disk space usage. Go ahead and pay attention to more wonderful things!
Go language custom DNS resolver practice yyds dry inventory
[UVM foundation] UVM_ Driver member variable req definition
Porphyrin based polyimide ppbpis (ppbpi-pa, ppbpi-pepa and ppbpi-pena); Crosslinked porphyrin based polyimide (ppbpi-pa-cr, ppbpi-pepa-cr, ppbpi-pena-cr) reagent
Solution to the problem of multi application routing using thinkphp6.0
Google Earth Engine(GEE) 01-中输入提示快捷键Ctrl+space无法使用的问题
Summary of domestic database examination data (continuously updated)
Liquid crystal texture diagram of purple solid mm-tpp-10c methacrylic acid decanoxy tetraphenyl porphyrin and mm-tpp-12c methacrylic acid dodecanoxy tetraphenyl porphyrin - Qi Yue display
[UVM basics] connect of UVM_ Phase execution sequence
Cache usage
Request&Response
执行npm install -g serve时报错权限权限问题解决方案
Oracle creates stored procedures with return values and executes SQL calls
数据中心灾难恢复的重要参考指标:RTO和RPO
Golang source package collection
Jmeter压力测试-Web代理本地接口测试【教学篇】
记一次开发 pgadmin 时执行 Building the Web Assets 遇到的依赖安装问题