Implicit size of layout



  • Hi everybody!

    I have a problem with the implicit size of a layout... What I want to do:

    I have an application which shows its content in an application window; this content should be able to grow to a certain size; if the window gets bigger, the content should keep a fixed size and only the window should keep growing, showing more and more background.
    At the other hand, the window should not be able to shrink to much - it should always be bigger than the minimum size requested by the content. To my understanding all this can be implemented easily by using a layout:

    import QtQuick 2.7
    import QtQuick.Controls 2.1
    import QtQuick.Layouts 1.1
    
    ApplicationWindow {
        id: win
        visible: true
    
        property bool small: true
    
        minimumWidth: layout.implicitWidth
        minimumHeight: layout.implicitHeight
    
        ColumnLayout {
            id: layout
            anchors.fill: parent
    
            Rectangle {
                id: rect
                Layout.fillWidth: true
                Layout.fillHeight: true
                Layout.alignment: Qt.AlignCenter
                Layout.minimumWidth: small ? 200 : 300
                Layout.minimumHeight: small ? 300 : 400
                Layout.maximumWidth:  500
                Layout.maximumHeight: 600
                color: "black"
            }
        }
    
        Text {
            anchors.centerIn: parent
            color: "white"
            font.pixelSize: 10
            text:  "rect: " + rect.width + "/" + rect.height + "\n"
                 + "rect(min): " + rect.Layout.minimumWidth + "/" + rect.Layout.minimumHeight + "\n\n"
                 + "layout(impl): " + layout.implicitWidth + "/" + layout.implicitHeight + "\n\n"
                 + "win: " + win.width + "/" + win.height + "\n"
                 +  "win(min): " + win.minimumWidth + "/" + win.minimumHeight
    
        }
    
        MouseArea {
            id: mouseArea
            anchors.fill: parent
            onClicked: {
                small = !small
            }
        }
    }
    
    

    I use the implicit size of the layout as minimum size of the window (in my real application the content in the layout can be rather difficult, so I do not want to figure out the necessary minimum size by hand...), and a button to change the minimum size requirements of the content.

    The above program works as I want it most of the time; however, if I start it, resize the window by dragging one corner with the mouse, and only then begin the clicking, the implicit size of the layout goes to a fixed value, and does not change any more, independent of the minimum size requested by the layout content.
    It is not clear to me, why this is the case. Does anybody have an idea how to fix this?

    Thanks a lot!!!


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.