当前位置:网站首页>QT realizes multi screen and multi-resolution adaptation
QT realizes multi screen and multi-resolution adaptation
2022-06-12 08:33:00 【Pry the fulcrum of the future】
Here is only a brief description of the implementation idea .
Operating conditions
- Two screens , Different resolution .
- Qt Software
Ask questions
I wrote a software some time ago , There is self drawn content in the window .
The length units used in the self drawn content are all pixels . As one can imagine , On the developer's computer screen, the size meets the requirements . No problem at this point .
After the software development is completed, it will be sent to the customer , The customer runs on his computer , Also no problem , After all, the resolution is about the same .
Run the software on a computer equipped with a high-resolution display once in a while , stay 4k Under screen , The software has the following problems :
- Overall dimensions and some self drawn content ( Line shape ) Become small , The reason is that the screen resolution has increased , More dense pixels , The same number of pixels looks shorter , This is easier to understand .
- In addition to some self drawn content , Like words , But it doesn't get smaller . This is because when drawing text , Font size is set using setPointSize, Make the text drawn on any display the same size .
- The final result is , The text looks big , The graph becomes very small .
resolvent
Realize multi screen resolution adaptation
There are two situations to discuss here .
- Use only one screen
In this case , Just do the following :
- When drawing a graph , Draw in millimeters .
- Get screen resolution , Add length -> Pixel conversion function , Convert each length into pixel length and pass it to the drawing function .
In this way, the self drawing content adaptation under different resolutions can be realized .
- Use multiple screens with different resolutions
In this case , It involves the problem of window dragging .
When a software window is dragged from one window to another , It needs to be retouched .
The following work needs to be done :
- Design window resolution change notification signal
stay Qt No relevant notification mechanism was found in , We can do it in paint Function to detect whether the current screen of the window has changed , If there is a change , Send a signal . Here is an implementation code , Used to determine whether the main screen changes :
bool Global::checkIfScreenChanged()
{
static int screen_number = -1;
bool changed = false;
QWidget *w = mainWindow();
QDesktopWidget *dk = QApplication::desktop();
int new_screen_number = dk->screenNumber(w);
if (screen_number != new_screen_number)
{
screen_number = new_screen_number;
changed = true;
// A notice
emit sigScreenChanged(screen_number);
}
return changed;
}
- Rearrange and draw
After receiving the window screen change message , Re layout 、 draw .
Realization effect
The expected effect has been achieved .
Conclusion
Windows Software on , such as office、WPS All of them deal with multi-resolution and multi screen , You can open any of the above software and drag it from one window to another , Across the screen , The software will be rearranged . And we use this method to achieve the same effect .
Recently created a official account , Write articles regularly , Mainly Qt dependent . If you find the article useful , You can focus on that .
边栏推荐
猜你喜欢

网站Colab与Kaggle

js中的正则表达式

Hands on deep learning -- concise implementation code of weight decay

三国杀周边--------猪国杀题解

svg中viewbox图解分析

(p19-p20) delegate constructor (proxy constructor) and inheritance constructor (using)

安科瑞电动机保护器具有过载反时限、过载定时限、接地、起动超时、漏电、欠载、断相、堵转等功能

【动态内存管理】malloc&calloc和realloc和笔试题和柔性数组

Special notes on using NAT mode in VM virtual machine

vm虛擬機中使用NAT模式特別說明
随机推荐
【 pointeur avancé Ⅲ】 mise en œuvre de la fonction de tri rapide qsort& fonction de rappel en langage C
How to understand the production scheduling of APS system?
MYSQL中的触发器
(p15-p16) optimization of the right angle bracket of the template and the default template parameters of the function template
A brief summary of C language printf output integer formatter
Vscode download slow solution
Hands on learning and deep learning -- Realization of linear regression from scratch
What should be paid attention to when establishing MES system? What benefits can it bring to the enterprise?
ctfshow web 1-2
【进阶指针一】字符数组&数组指针&指针数组
Centso8 installing mysql8.0 (Part 2)
Triggers in MySQL
了结非对称密钥
Website colab and kaggle
API处理Android安全距离
(p17-p18) define the basic type and function pointer alias by using, and define the alias for the template by using and typedef
三国杀周边--------猪国杀题解
What exactly is APS? You will know after reading the article
Webrtc adding third-party libraries
在Tensorflow中把Tensor转换为ndarray时,循环中不断调用run或者eval函数,代码运行越来越慢!