Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Changing DPI scaling size of display make Qt application's font size get rendered bigger

I have created some GUI application using Qt. My GUI application contains controls like push button and radio button. When I run the application, buttons and fonts inside button looks normal. When I change the DPI scaling size of display from 100% to 150% or 200%, font size of controls rendered bigger but not control size (pushbutton, radio button) irrespective of resolution. Due to this the text inside controls were cut off. please see the attached image.

Qt application look when DPI scaling size set to 100%

Qt application look when DPI scaling size set to 100%

Qt application look when DPI scaling size set to 200%

Qt application look when DPI scaling size set to 200%

I am running my application in some tablets also. In tablets, DPI scale value should be more than 150% else everything will be shown very small.

I searched in the web for creating UI application in Qt irrespective of resolution and DPI scale value but no luck. So I am posting my questing here. Please let me know if there is some way to get rid of this.

like image 876
Arun Avatar asked Dec 09 '13 06:12

Arun


People also ask

What does high DPI scaling override do?

High DPI scaling override Application: The application will be unaware of high DPI and will not be scaled; System: The application will again be unaware of high DPI and the system will scale it; System (Enhanced): This is only available in Windows 10 (1703)+.

What does high DPI scaling mean?

High DPI displays have increased pixel density, compared to standard DPI displays. Pixel density is measured in Dots per Inch (DPI) or Pixels per Inch (PPI), and is determined by the number of display pixels and their size.

Should I disable display scaling on high DPI?

But sometimes this feature for some specific apps can cause compatibility issues, unreadable texts, blurry signs, and ultimately app crashes. It is quite a headache if you are working on a 2160p resolution or higher. There are many ways to disable the default display scaling feature on High DPI settings.

How do I change font size in Qt?

Select Fonts & Colors tab. Under the Font heading after where it says Family: select Source Code Pro from the dropdown menu as marked by the mouse cursor in the below screenshot. After where it says Size: select 10 from the dropdown menu. Font size 10 is the best font size in my Qt Creator.


1 Answers

High DPI support is enabled from Qt 5.6 onward.

Setting QGuiApplication::setAttribute(Qt::AA_EnableHighDpiScaling) in your application source code allows automatic high-DPI scaling.

NOTICE: To use the attribute method, you must set the attribute before you create your QApplication object:

#include <QApplication>  int main(int argc, char *argv[]) {     QApplication::setAttribute(Qt::AA_EnableHighDpiScaling);      QApplication app(argc, argv);        return app.exec(); } 
like image 70
Nicolas Holthaus Avatar answered Oct 07 '22 01:10

Nicolas Holthaus