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()?
A layout can not be hidden since they are not widgets and does not have a setVisible() function. You have to create a widget that you can hide, that contains the layout and the other widgets that should be hidden, then you hide the widget instead of the layout.
Widgets are the primary elements for creating user interfaces in Qt. Widgets can display data and status information, receive user input, and provide a container for other widgets that should be grouped together. A widget that is not embedded in a parent widget is called a window.
The tree-like organization of QWidgets (and in fact of any QObjects ) is part of the memory management strategy used within the Qt-Framework. Assigning a QObject to a parent means that ownership of the child object is transferred to the parent object. If the parent is deleted, all its children are also deleted.
If the width won't change afterwards, you can use setFixedWidth : widget->setFixedWidth(165); Similarly, to change the height without changing the width, there is setFixedHeight . Never use fixed width!
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.
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.)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With