Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

improper scaling of Qt Desktop application in windows 10

I'm writing a simple Qt (Widgets) Gui application for windows 10. I'm using the 5.6.0 beta version of Qt.

The problem I'm having is that it isn't scaling right to the screen of my surfacebook at all:

enter image description here

It's a bit hard to tell because SO scales the image, but notice how small the dock widget title bar controls are relative to the window title bar controls.

This link from Qt talks about scaling, but it's mostly focuses on qml/qtQuick and mobile applications in general, and additionally seems to imply that in a desktop QtWidgets application, QPainter will automatically determine the proper scaling, which it clearly is not.

What's the best way to ensure that desktop, non-qml Qt applications scale properly on high-DPI monitors, specifically with windows 10?

like image 941
Nicolas Holthaus Avatar asked Mar 05 '16 16:03

Nicolas Holthaus


1 Answers

Qt has recently released a blog post about this issue here.

High DPI support is enabled from Qt 5.6 onward. On OS X platforms, there is native support for High-DPI. On X11/Windows/Android, there are two methods to enable high-DPI detection per the blog post:

  1. Set an environment variable
  2. Setting an attribute in the program source code

Setting QT_AUTO_SCREEN_SCALE_FACTOR=1 in your system environment variables will fix the scaling issue.

Additionally, setting QGuiApplication::setAttribute(Qt::AA_EnableHighDpiScaling); in your application source code should also allow automatic high-DPI scaling.

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

#include <QApplication>

int main(int argc, char *argv[])
{
    QApplication::setAttribute(Qt::AA_EnableHighDpiScaling);

    QApplication app(argc, argv);   
    return app.exec();
}
like image 113
Nicolas Holthaus Avatar answered Oct 08 '22 03:10

Nicolas Holthaus