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