問題描述
我使用 Qt 創建了一些 GUI 應用程序.我的 GUI 應用程序包含按鈕和單選按鈕等控件.當我運行應用程序時,按鈕內的按鈕和字體看起來很正常.當我將顯示的 DPI 縮放大小從 100% 更改為 150% 或 200% 時,無論分辨率如何,控件的字體大小都會變大,但控件大小(按鈕、單選按鈕)不會.由于這個原因,控件中的文本被截斷了.請看附圖.
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 應用程序在 DPI 縮放大小設置為 100% 時的外觀
Qt application look when DPI scaling size set to 100%
Qt 應用程序在 DPI 縮放大小設置為 200% 時的外觀
Qt application look when DPI scaling size set to 200%
我也在一些平板電腦上運行我的應用程序.在平板電腦中,DPI 比例值應大于 150%,否則所有內容都會顯示得很小.
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.
我在網上搜索在 Qt 中創建 UI 應用程序,而不管分辨率和 DPI 比例值,但沒有運氣.所以我在這里發布我的任務.請告訴我是否有辦法擺脫這種情況.
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.
推薦答案
從 Qt 5.6 開始啟用高 DPI 支持.
High DPI support is enabled from Qt 5.6 onward.
在應用程序源代碼中設置 QGuiApplication::setAttribute(Qt::AA_EnableHighDpiScaling)
允許自動高 DPI 縮放.
Setting QGuiApplication::setAttribute(Qt::AA_EnableHighDpiScaling)
in your application source code allows automatic high-DPI scaling.
注意:要使用屬性方法,您必須在創建QApplication
對象之前設置屬性:
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();
}
這篇關于更改顯示的 DPI 縮放大小會使 Qt 應用程序的字體大小變得更大的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!