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. Implicit size of layout
Forum Updated to NodeBB v4.3 + New Features

Implicit size of layout

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

    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!!!

    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