How to hide completely a QGridLayout?
I have a button followed by a QGridLayout
full of widg开发者_如何学运维ets.
I want to show/hide QGridLayout
at every button click, but reading documentation of QGridLayout
I see there's no show()
/hide()
implementation, also no setVisible()
method available.
How do I achieve this?
Layouts only affect the size/position of the widgets added to them - for visibility (and anything else - event handling, focus, enable+disable) you care about the parent widget, as mentioned above. QLayout::parentWidget() gives you the widget which owns the layout, which you can then show and hide.
You didn't mention which version of Qt you're using. (I'm looking at the 4.4 documentation.)
I haven't tried this, but here are two ideas:
QGridLayout
inherits the functionQLayoutItem::widget()
. If your layout is a widget, this will return aQWidget*
on which you can callshow()
orhide()
.- If your
QGridLayout
is not aQWidget
, you can nest it within aQWidget
, and you canshow()
/hide()
that widget instead.
I assume you have multiple QGridLayout
instances, only one should be visible based on the button that has been clicked. You can use a QStackedWidget
for this:
The QStackedWidget class provides a stack of widgets where only one widget is visible at a time.
Then, for each widget in the QStackedWidget
you should associate a separate QGridLayout
.
See the Qt documentation for more details
精彩评论