Initially hidden control in Qt Creator

28,792

Solution 1

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.

Solution 2

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.

Share:
28,792
Daniel
Author by

Daniel

Updated on October 21, 2020

Comments

  • Daniel
    Daniel over 3 years

    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?

  • Daniel
    Daniel over 12 years
    I already done this, I was looking for alternative way. the custom slot is unneeded, toggled(bool) connected to setShown(bool) works correctly.
  • Nicholas Smith
    Nicholas Smith over 12 years
    In that case I'd suggest doing a dig into the properties editor in Designer to implement the setHidden/setShown property for it.
  • Guimoute
    Guimoute over 4 years
    I would advise against modifying the .ui file because it's generated automatically. Just add self.ui.widget_name.setVisible(False) in your __init__.