当前位置:网站首页>QT notes - realize form adaptation
QT notes - realize form adaptation
2022-07-24 12:04:00 【Cool breeze in the old street °】
We want all controls to change with the size of the window .
The first method :
Ideas :
1. We need to get all the controls
m_Widget = this->findChildren<QWidget*>(QString(), Qt::FindDirectChildrenOnly);
2. We need to know the location and size of all controls
3. rewrite resizeEvent event
protected:
void resizeEvent(QResizeEvent* event);
4. Get the zoom ratio of the main window
5. Let each control * The zoom ratio
#include "ui_QtEventFilter.h"
#include <QResizeEvent>
#include <QRect>
class QtEventFilter : public QWidget
{
Q_OBJECT
public:
QtEventFilter(QWidget *parent = Q_NULLPTR);
~QtEventFilter();
protected:
void resizeEvent(QResizeEvent* event);
private:
Ui::QtEventFilterClass ui;
QList<QWidget*> m_Widget; // Store all child controls
QMap<QWidget*, QRect> m_WidgetRect; // Save the initial size of each child control
};
#include "QtEventFilter.h"
#include <QDebug>
QtEventFilter::QtEventFilter(QWidget *parent)
: QWidget(parent)
{
ui.setupUi(this);
// Get all the controls
m_Widget = this->findChildren<QWidget*>(QString(), Qt::FindDirectChildrenOnly);
// Traverse the control to get the size and position
foreach(auto widget, m_Widget)
{
m_WidgetRect.insert(widget, QRect(widget->x(), widget->y(), widget->width(), widget->height()));
}
}
QtEventFilter::~QtEventFilter()
{
}
void QtEventFilter::resizeEvent(QResizeEvent* event)
{
float width = this->width() * 1./ 600;
float height = this->height() * 1./400;
for ( auto it= m_WidgetRect.begin(); it != m_WidgetRect.end(); it++ )
{
it.key()->setGeometry(it.value().x() * width, it.value().y() * height, it.value().width() * width, it.value().height() * height);
}
QWidget::resizeEvent(event);
}
The second method :
Find the current UI file , Click a button in the picture , One is horizontal layout , A vertical layout , This can also change with the size of the window 
Reference blog :
https://blog.csdn.net/hua12134/article/details/84888250
边栏推荐
- Hash - 15. Sum of three numbers
- String - Sword finger offer 05. replace spaces
- Microsoft SQL Server database language and function usage (XII)
- [TA frost wolf umay - "hundred people plan] Figure 3.3 surface subdivision and geometric shader large-scale grass rendering
- [Commons beanautils topic] 004 beanautils topic
- Optimization method of "great mathematics for use" -- optimal design of Cascade Reservoir Irrigation
- Nacos permissions and databases
- L1-059 ring stupid bell
- Guys, do you need to configure anything to use rocksdb when using flinksql? Or do you need any jar packages
- Record a garbage collection and analysis of gceasy
猜你喜欢

在kuborad图形化界面中,操作Kubernetes 集群,实现mysql中的主从复制

What is prescaler in STM32

Shell script "< < EOF" my purpose and problems

Is there any charge for PDF processing? impossible!

基于ARM和FPGA的数字示波器设计——QMJ

Install MariaDB columnstore (version 10.3)

MySQL advanced (XVII) cannot connect to database server problem analysis

One week's wonderful content sharing (issue 13)

4*4图片权重的收敛规则

Easy to use example
随机推荐
L1-064 估值一亿的AI核心代码
Blue team resource collection
1184. 公交站间的距离 : 简单模拟题
Convergence rules for 4 * 4 image weights
Quick check list of various XSS payloads
Shell Scripting tips
[data mining engineer - written examination] sheen company in 2022
Open source DNS software powerdns BIND9 mydns
Linked list - Sword finger offer interview question 02.07. linked list intersection
栈顶与栈底
leetcode:51. N 皇后
Grep actually uses ps/netstat/sort
Detailed OSPF configuration of layer 3 switch / router [Huawei ENSP experiment]
Hash - 349. Intersection of two arrays
Install JMeter
js图像转base64
String -- 344. Reverse string
三、MFC消息映射机制实现原理
Please ask whether Oracle CDC does not support checkpointing. When the task is suspended and restarted during the real-time collection process, is the data changed
Is there any charge for PDF processing? impossible!