Change the window's size through a button (flickers)
Unsolved
QML and Qt Quick
-
Hello everyone,
I have written a Component "Resize.qml", which provides a button resizing a window/Pane/Rectangle ... attached to it.
Logic seems to work fine as it works as exspected with a Pane in a ApplicationWindow. But actually I made it to resize the ApplicationWindo itself, which also does work in general, but flickers while resizing.main.qml import QtQuick 2.10 import QtQuick.Controls 2.3 ApplicationWindow { id: root width: 800; height: 600 visible: true Resize { width: 18 height: 18 anchors.horizontalCenter: parent.right anchors.verticalCenter: parent.top corner: Resize.Corner.TopRightCorner source: "verkleinern.png" target: root } }
Resize.qml import QtQuick 2.10 Item { id: root enum Corner { TopLeftCorner, TopRightCorner, BottomLeftCorner } property alias source: buttonIcon.source property int corner : Resize.Corner.TopLeftCorner property var target: null Image { id: buttonIcon anchors.fill: parent } MouseArea { anchors.fill: parent drag.target: root onPositionChanged: { if(drag.active) { switch(corner) { case Resize.Corner.TopLeftCorner: { root.target.width -= mouseX; root.target.x += mouseX; root.target.height -= mouseY; root.target.y += mouseY; break; } case Resize.Corner.TopRightCorner: { root.target.width += mouseX; root.target.height -= mouseY; root.target.y += mouseY; break; } } } } } }
If you drag the Button in the upper right corner around, the window's size follows it. It only works perfect if you drag the button really really slow, in the other case it flickers a lot, which I haven't noticed in a nested window.
Does anyone have a solution for this?
-
Use https://doc.qt.io/qt-6/qwindow.html#startSystemResize instead. You can call it from QML.