简体   繁体   中英

How to hide/show a QLabel and QTextEdit at the same time in my Qt application?

I am working on a hide/show feature for my console in my Qt GUI application. The console consists of 2 widgets; QLabel and QTextEdit. Do I need to add the QLabel and QTextEdit to a QWidget in order to show/hide them, or is there a better way?

So basically I am looking for a container such as 'JPanel' in Java...

Do I need to add the QLabel and QTextEdit to a QWidget in order to show/hide them, or is there a better way?

Multiple methods are possible here. You can, as you suggest, create a parent QWidget and add the QLabel and QTextEdit to a QWidget. Calling show and hide on the parent widget will affect its children.

Another method would be to have a slot function, which when an action is called, the slot calls show / hide on the 2 widgets.

Neither is right or wrong and depends upon the overall design of your application.

Ok, I think you need to use a layout (horizontal / vertical):

The simplest way to arrange objects on a form is to place them in a horizontal or vertical layout. Horizontal layouts ensure that the widgets within are aligned horizontally; vertical layouts ensure that they are aligned vertically.

Horizontal and vertical layouts can be combined and nested to any depth. However, if you need more control over the placement of objects, consider using the grid layout.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM