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:
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?
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:
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();
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With