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. Ignore invisible items inside Layout
Forum Updated to NodeBB v4.3 + New Features

Ignore invisible items inside Layout

Scheduled Pinned Locked Moved QML and Qt Quick
12 Posts 5 Posters 9.5k Views 1 Watching
  • 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.
  • R Offline
    R Offline
    rominf
    wrote on last edited by
    #1

    Hi.
    I have several buttons on the form, some of them should be hidden in some conditions. When I hide button placed inside ColumnLayout I get hole like:
    !http://i.imgur.com/2o2FX5i.png(this)!
    instead of expeced:
    !http://i.imgur.com/LDPAKMt.png(that)!
    Here is the code:
    @import QtQuick 2.0
    import QtQuick.Controls 1.0
    import QtQuick.Layouts 1.0

    Rectangle {
    width: 256
    height: 128
    ColumnLayout
    {
    anchors.margins: 8
    anchors.fill: parent
    Button
    {
    Layout.fillWidth: true
    }
    Button
    {
    visible: false
    Layout.fillWidth: true
    }
    Button
    {
    Layout.fillWidth: true
    }
    }
    }@

    How can I say Layout to ignore invisible items?

    PS: Real app, that requires this: "my old thread":http://qt-project.org/forums/viewthread/27605/#124749

    1 Reply Last reply
    0
    • A Offline
      A Offline
      Alek Śmierciak
      wrote on last edited by
      #2

      Don't know about the intention of QtQuick 5.0 Layouts module author (I'm wondering about this one myself, and also about the transition applicable to the Layouts elements), but a workaround is to use "Column":http://qt-project.org/doc/qt-5.0/qtquick/qml-qtquick2-column.html element instead, which will "hide" invisible elements:

      bq. If an item within a Column is not visible, or if it has a width or height of 0, the item will not be laid out and it will not be visible within the column.

      1 Reply Last reply
      0
      • R Offline
        R Offline
        rominf
        wrote on last edited by
        #3

        I know, it worked with Columns well, but I want to use layout features. I'm not satisfied how my app (see PS of my question) looked with Column and Grid.

        1 Reply Last reply
        0
        • S Offline
          S Offline
          SlimIT
          wrote on last edited by
          #4

          Have you tried to set the enabled property of the item to false ?

          1 Reply Last reply
          0
          • R Offline
            R Offline
            rominf
            wrote on last edited by
            #5

            SlimIT, yes, I have tried.
            It doesn’t work with both (enabled, visible) properties set to false.

            1 Reply Last reply
            0
            • S Offline
              S Offline
              SlimIT
              wrote on last edited by
              #6

              rominf,

              I'm not sure but may be the use of Column Item is better that ColumnLayout

              1 Reply Last reply
              0
              • R Offline
                R Offline
                rominf
                wrote on last edited by
                #7

                In this primitive situation as in question, of course I can use Column instead of ColumnLayout. But it's hard to get good looking layout in my real situation (see PS in question) with Grid.

                Are there other suggesitions?

                1 Reply Last reply
                0
                • J Offline
                  J Offline
                  janarve
                  wrote on last edited by
                  #8

                  Hi.
                  There was a bug wrt invisible items. This is fixed now. Your example code works as you expect now.

                  1 Reply Last reply
                  0
                  • J Offline
                    J Offline
                    Jens
                    wrote on last edited by
                    #9

                    I can confirm that this is no longer an issue in the release branch for 5.1. Note that if you do not want space left between the visible buttons you would also need to add a spacer item at the bottom of your layout to take up the remaining space.

                    1 Reply Last reply
                    0
                    • R Offline
                      R Offline
                      rominf
                      wrote on last edited by
                      #10

                      janarve, Jens
                      Thank you for updated information!

                      1 Reply Last reply
                      0
                      • A Offline
                        A Offline
                        Alek Śmierciak
                        wrote on last edited by
                        #11

                        janarve, Jens, thanks for the info. Are QtQuick Layouts going to have an add, move or displaced transition then? What is the intended difference between the Layouts (GridLayout, ColumnLayout, RowLayout) and the standard positioners (Grid, Column, Row)?

                        1 Reply Last reply
                        0
                        • J Offline
                          J Offline
                          janarve
                          wrote on last edited by
                          #12

                          @Alek: Animations are something we consider, but nothing has been decided yet.
                          I suggest you can look at the blog post to read about the differences between the Qt Quick Layouts and the Qt Quick Positioners: http://blog.qt.digia.com/blog/2013/05/16/introducing-qt-quick-layouts/

                          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