What's the difference in Qt between setVisible

2020-06-30 05:02发布

Please excuse this potentially noobish question but when trying to hide a QWidget what is the difference between calling setVisible(False), setShown(False) and hide()?

2条回答
虎瘦雄心在
2楼-- · 2020-06-30 05:34

There is no difference. They are just different ways of achieving the same thing. (Actually setShown isn't really part of the API, it looks like it's a compatibility thing from Qt 3, so best not to use it.)

查看更多
家丑人穷心不美
3楼-- · 2020-06-30 05:35

show() is just a convenience function for setVisible(true).

Similarly hide() is equivalent to setVisible(false)

Internally, the same code is used to render your view.

See http://doc.qt.io/archives/qt-4.7/qwidget.html#show as an example. According to it,

void QWidget::show () [slot] Shows the widget and its child widgets. This function is equivalent to setVisible(true).

You'll find lots of such functions in Qt to just make things more intuitive, especially when it comes to widgets and views.

查看更多
登录 后发表回答