0

The title bar for my QQuickView Qt application is too big when I move the window to my secondary monitor. It displays correctly on my primary monitor. The title bar is the correct size if I use QWidget instead of QQuickView.

Is it possible to make the title bar display correctly for a QQuickView application? If so, how?

I am using PySide2 version 5.15.0 on Windows 10 version 1803. My primary monitor DPI is set to 125%, and my secondary monitor is set to 100%. The application is running as "per-monitor DPI aware". The Qt documentation on high DPI support didn't have anything helpful for resolving this. I played around with various DPI settings and environment variables.

test.py

from PySide2 import QtWidgets
from PySide2.QtCore import QUrl
from PySide2.QtQuick import QQuickView

if __name__ == '__main__':
    app = QtWidgets.QApplication([])

    view = QQuickView()
    view.setResizeMode(QQuickView.SizeRootObjectToView)
    view.setSource(QUrl('view.qml'))
    view.show()

    app.exec_()

view.qml

import QtQuick 2.0

Rectangle {
    width: 300
    height: 200
    color: "green"

    Text {
        text: "Hello World"
        anchors.centerIn: parent
    }
}
eyllanesc
  • 235,170
  • 19
  • 170
  • 241
sourcenouveau
  • 29,356
  • 35
  • 146
  • 243

1 Answers1

0

Solution

Thanks to @eyllanesc for the hint on how to try a different renderer.

Configure Qt to use the ANGLE renderer by adding one of the following lines before instantiating the QApplication object:

QtWidgets.QApplication.setAttribute(Qt.AA_UseOpenGLES)
os.environ['QT_OPENGL'] = 'angle'

See Qt 5 on Windows ANGLE and OpenGL for implications.

Background

There seem to be some longstanding issues with scaling the non-client area (title bar) properly in Qt Quick applications with the OpenGL renderer on Windows.

Qt bug report QTBUG-78143 is about non-client items not being scaled when dpiawareness is 2. The bug is closed as a problem with Windows that Microsoft is aware of, but has not fixed.

There is also the older QTBUG-65804 which talks about the same problem.

QTBUG-68712 talks about implementing a new Windows value, DPI_AWARENESS_CONTEXT_PER_MONITOR_AWARE_V2, but that it would bring back an older bug until Microsoft fixes something.

I found an SO question which has a lot of discussion too.

sourcenouveau
  • 29,356
  • 35
  • 146
  • 243
  • 1
    You say: *but I am a Qt newbie and I don't know how to do that!*, then try add `os.environ["QT_OPENGL"] = "angle"` before `app = QtWidgets.QApplication([])`. See https://doc.qt.io/qt-5/windows-requirements.html#graphics-drivers – eyllanesc Jun 23 '20 at 04:40