Hide qml item?



  • How can I hide an item in qm. I mean really hiding it, so e.g. a Column wont display empty space for its height.



  • @manuelschneid3r

    Set the visible property of the item to false. For example, this code produces a column that consists of two columns of three rectangles, but only one takes space because the other one is not visible:

    import QtQuick 2.3
    import QtQuick.Controls 1.2
    import QtQuick.Window 2.2
    
    ApplicationWindow {
        title: qsTr("Hello World")
        Column {
            Column {
                spacing: 2
                visible: false
                Rectangle { color: "red"; width: 50; height: 50 }
                Rectangle { color: "green"; width: 20; height: 50 }
                Rectangle { color: "blue"; width: 50; height: 20 }
            }
            Column {
                spacing: 2
                visible: true
                Rectangle { color: "red"; width: 50; height: 50 }
                Rectangle { color: "green"; width: 20; height: 50 }
                Rectangle { color: "blue"; width: 50; height: 20 }
            }
        }
    }
    

    Conversely, you could also hide in the same way, for example, one of the rectangles of one of the columns. If you do that and change each column's visible property to true or false you'll see the difference: one column will have two elements, the other will have three.



  • This is what I did. Later I discovered that the problem was that the height of the parent relied on the cildren rect, which is somehow buggy. Thank you for clearifying this.


Log in to reply
 

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