Ignore invisible items inside Layout
-
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.0Rectangle {
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
-
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.
-
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.
-
Have you tried to set the enabled property of the item to false ?
-
SlimIT, yes, I have tried.
It doesn’t work with both (enabled, visible) properties set to false. -
rominf,
I'm not sure but may be the use of Column Item is better that ColumnLayout
-
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?
-
Hi.
There was a bug wrt invisible items. This is fixed now. Your example code works as you expect now. -
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.
-
janarve, Jens
Thank you for updated information! -
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)?
-
@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/