Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What's the difference in Qt between setVisible, setShown and show/hide

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()?

like image 785
Jay Avatar asked Aug 29 '12 12:08

Jay


People also ask

How do I hide layout in Qt?

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.

What is QWidget in Qt?

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.

What is QWidget * parent?

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.

How do I change the size of a widget in Qt?

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!


2 Answers

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.

like image 132
Pramod Avatar answered Oct 08 '22 07:10

Pramod


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.)

like image 33
Dan Milburn Avatar answered Oct 08 '22 06:10

Dan Milburn