当前位置:网站首页>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
边栏推荐
- 6k+ star,面向小白的深度学习代码库!一行代码实现所有Attention机制!
- gcc -l参数和-L参数的区别
- Open source DNS software powerdns BIND9 mydns
- Chapter 1 Introduction
- Svn server and client installation (Chinese package) and simple use
- 2 万字详解,吃透 ES!
- Detailed explanation of stat function
- CCF 1-2 question answering record (2)
- Collision, removal and cleaning
- [data mining engineer - written examination] sheen company in 2022
猜你喜欢

[TA frost wolf umay - "hundred people plan] Figure 3.3 surface subdivision and geometric shader large-scale grass rendering

链表——142. 环形链表 II

Shengxin weekly issue 37
![[mathematical basis of Cyberspace Security Chapter 9] finite field](/img/2b/27ba1f3c6ec2ecff4538f9a63a79e8.jpg)
[mathematical basis of Cyberspace Security Chapter 9] finite field

Miss waiting for a year! Baidu super chain digital publishing service is limited to 50% discount

Cgo+gsoap+onvif learning summary: 9. Go and C conduct socket communication and onvif protocol processing

安装jmeter

Remember to optimize my personal blog once

In kuborad graphical interface, operate kubernetes cluster to realize master-slave replication in MySQL

JMeter while controller
随机推荐
Hash - 1. Sum of two numbers - some people fall in love during the day, some people watch the sea at night, and some people can't do the first question
Svn server and client installation (Chinese package) and simple use
在kuborad图形化界面中,操作Kubernetes 集群,实现mysql中的主从复制
Experience of redis deepwater area -- Interview reference
Why is the datetime type field 8 hours earlier when I use flinkcdc to read MySQL's binlog?
MES系统设备管理概述(中)
Microservice - eruka
Makefile quick use
利用huggingface模型翻译英文
In kuborad graphical interface, operate kubernetes cluster to realize master-slave replication in MySQL
L2-011 玩转二叉树
One of his birds sold for 60million -- the collection of eight mountain people in the Ming and Qing Dynasties
[C and pointer Chapter 11] dynamic memory allocation
NFT digital collection system construction - app development
Types and history of bugs in it circle
An analysis of the CPU surge of an RFID tag management system in.Net
Collision, removal and cleaning
CCF 1-2 question answering record (2)
字符串——剑指 Offer 05. 替换空格
Top and bottom of stack