开发者

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 function QLayoutItem::widget(). If your layout is a widget, this will return a QWidget* on which you can call show() or hide().
  • If your QGridLayout is not a QWidget, you can nest it within a QWidget, and you can show() / 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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜