简体   繁体   中英

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?

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.

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.

I couldnt find anything useful, and after some time wasted, I found the solution. So maybe not so wasted time.

The easiest way found inside your Qt Designer program, select your QLineEdit class inside the.ui file you are making. And inside your Property Editor scroll down untill you see a dropdown menu called QLineEdit , go down until you see text sub menu and inside there, look for an option called: echoMode . Click on the option and choose Password .

There you go. All done.

Below are some examples so you do not get lost.

Thanks!!

QT Designer - 属性编辑器 Qt Designer - 密码示例

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