Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. QML and Qt Quick
  4. Change the window's size through a button (flickers)
QtWS25 Last Chance

Change the window's size through a button (flickers)

Scheduled Pinned Locked Moved Unsolved QML and Qt Quick
qmlresizeflickering
3 Posts 3 Posters 1.1k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • L Offline
    L Offline
    Leon_2001
    wrote on last edited by
    #1

    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?

    1 Reply Last reply
    0
    • JarrodJ Offline
      JarrodJ Offline
      Jarrod
      wrote on last edited by
      #2

      I'm getting the same flickering with basically the same approach. Would like to know if there is a way to get a smooth resizing.

      1 Reply Last reply
      0
      • GrecKoG Offline
        GrecKoG Offline
        GrecKo
        Qt Champions 2018
        wrote on last edited by
        #3

        Use https://doc.qt.io/qt-6/qwindow.html#startSystemResize instead. You can call it from QML.

        1 Reply Last reply
        0

        • Login

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • Users
        • Groups
        • Search
        • Get Qt Extensions
        • Unsolved