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. How to detect when the user has resized the window?

How to detect when the user has resized the window?

Scheduled Pinned Locked Moved Unsolved QML and Qt Quick
1 Posts 1 Posters 214 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.
  • J Offline
    J Offline
    Jack Hill
    wrote on last edited by Jack Hill
    #1

    Hi everyone, I'm writing an app where the main window is usually resized based on the size of the content currently shown. But if the user has resized the window, then the window enters a "fixed resize" mode, where the app should not resize itself automatically.

    Is it possible to detect when the user has resized a window?

    This is the code that I've tried so far:

    import QtQuick 2.0
    import QtQuick.Controls 2.15 as QQC2
    
    QQC2.ApplicationWindow {
        id: root
        visible: true
        width: 300
        height: 240
    
        color: "steelblue"
    
        property bool resizedByApp: false
        property bool fixedSizeMode: false
    
        onFixedSizeModeChanged: console.log("fixedSizeModeChanged", fixedSizeMode)
    
        onWidthChanged: {
            if (!resizedByApp) {
                fixedSizeMode = true
            }
        }
    
        onHeightChanged: {
            if (!resizedByApp) {
                fixedSizeMode = true
            }
        }
    
        function resizeApp(newWidth, newHeight) {
            if (fixedSizeMode) {
                return
            }
            root.resizedByApp = true
            width = newWidth
            height = newHeight
            root.resizedByApp = false
        }
    
        QQC2.Button {
            text: "Resize me"
            onClicked: resizeApp(500, 500)
        }
    }
    

    but when I click on the button, the window is resized before resizedByApp is set to true.

    (btw I'm using Qt 5.15.9)

    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