Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Initially hidden control in Qt Creator

I want to make a group box shown only when a radio button is selected.
I managed to do that by connecting the toggled(bool) signal of the radio button to the setShown(bool) slot of the group box.
The problem is that the radio button is initially deselected but the group box is initially shown so I have to select/deselect the radio button to make it disappear.
Is there any way I can make the group box initially invisible in Qt Creator Designer without having to do it in code?

like image 215
Dani Avatar asked Oct 19 '11 12:10

Dani


People also ask

How do I hide pushbutton in Qt?

There is no property called hide, but there is one called "visible" that does what you want. See the QWidget (Since QPushButton is a QWisget) docs for more information.

How do you hide QLabel?

You can't control the visible property, But if you want to make QLabel looks invisible as default, just set the width/height property to 0 .

How do I hide QWidget?

Show() and hide() widget Each Qt widget has a . setVisible method which can be used to toggle that widget's visibility. >> However, compound or nested widgets can only become invisible when all their child widgets are >>also invisible.

How do you hide the spacer in Qt?

Try putting the button you want to hide and unhide in another layout. In that layout along with the button put a spacer. Call Button hide and spacer will take over. Spacer takes over hidden button's space.


2 Answers

You can't.

The visible property seems to be voluntarily removed from the property editor of Qt Designer and you can't add it back.

You can add the property manually to the .ui file by adding the following XML block inside the node for the widget you want to hide:

<property name="visible">    <bool>false</bool> </property> 

But the widget won't be visible or movable when you reopen the interface with the designer. It will still appear in the widget hierarchy though.

like image 197
alexisdm Avatar answered Nov 09 '22 18:11

alexisdm


You can try playing round with the Properties (look at setHidden), but it's much easier to do it in the code.

So you'd do:

ui setup code ui->groupBox->setHidden(true)  radio button slot if true ui->groupBox->setHidden(false) else if false ui->groupBox->setHidden(true) 

That's the easiest way really, I've never had much luck with adding properties in Designer that Qt already uses.

like image 41
Nicholas Smith Avatar answered Nov 09 '22 18:11

Nicholas Smith