Initially hidden control in Qt Creator - qt

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.

Related

How to hide a widget created by QtDesigner "design" mode programmatically?

I want to know how to create a QLabel in QtCreator Design mode that is hidden by default?In the properties list in the right hand side panel , there's not any option regarding visibility and also adding label->hide() to setupUi function (after compiling ui file and adding to the project headers) makes no difference.
Designer doesn't expose the visible property. You could hand-edit the UI file, but that will be overwritten next time you edit in Designer. It's best to leave it visible in Designer, and just write a line of code after you call setupUi() to hide the widget you don't want to be initially shown.

QDockWidget form in Qt Creator Designer

I'm using Qt Creator 4.5.0 and am trying to create a QDockWidget that I could modify in the builtin designer (I do this all the time with QDialogs and QMainWindows, so this is the first time trying with a QDockWidget). But I'm having no luck with being able to add any widget elements of any kind to the QDockWidget.
Here are the steps I've taken
In the Projects tree on the left, right click on the project and select "Add New..."
In the window that pops up select "Qt" on the left side, then select "Qt Designer Form Class", then select "Choose"
On this page expand the section for "Widgets", then select "QDockWidget", then select "Next"
On this page give the class a name (for me it's "ImageFilesDockWidget"), then click "Next"
On this page select "Finish" to add the files to the project.
From here the "ImageFilesDockWidget.ui" file will automatically show up, so I tried to add some widgets to the view, but nothing would get added. For example, if I clicked and dragged a pushbutton into the center of the dockwidget, then it displayed a red circle with a line through it to indicate I couldn't add the item.
If anyone has run into this problem and knows how to make it work, then that'd be an immense help to me.
Thanks in advance.
update
Currently I'm able to use the designer to customize a standard QWidget object (call it "ImageFilesWidget.ui"). So at the moment my solution is to add a standard QDockWidget to my QMainWindow in the designer, then (still in the designer) I promote the dockWidgetContents from a standard QWidget to my ImageFilesWidget class.
It seems like the problem is when qtcreator 4.5 creates the dockwidgets ui file for you, it doesn't include the "dockWidgetContents" widget that is included in previous versions. Just manually put <widget class="QWidget" name="dockWidgetContents"/> under the "windowTitle" property of the dockwidget and you'll be able to add ui elements to it.

Is there a way to show tooltip on disabled QWidget

I have a Qt form, where I have a button and menu. For various reasons I can disable certain elements, e.g button or some actions in the menu.
Is there a way I could show a tooltip or when the mouse is hovered over the disabled button or menu item with an explanation as to why it is disabled?
I am using Qt 4.8.
Thanks!
You can set the tooltip dynamically based on the state of the QWidget or by simply toggling both at the same time. Upon disabling/enabling the widget from somewhere just call QWidget::setToolTip(...) with the QString you want the tooltip to display when hovering with the mouse over the given widget. For example if you have a public slot called toggleButton(bool toggleFlag) which toggles the enable-setting of a button you can do:
void MyWidget::toggleButton(bool toggleFlag) {
this->ui->myButton->setEnabled(toggleFlag);
this->ui->myButton->setToolTip(toggleFlag ? QString("Enabled wohoo!") : QString("Disabled because I like it"));
}
You can of course do also change the tooltip by calling QWidget::isEnabled() and act upon its return value. Since you haven't given any code I can only assume how you toggle your button(s) so that's all I can give you for now.
UPDATE: It was pointed in the comments that tooltips don't work with disabled widgets due not receiving mouse events. Both statements are not true (note that I have used the same tooltip message since due to lack of minimal working example I didn't want to write a whole new project from scratch and used an existing one of mine instead):
Hovering a disabled button triggers the tooltip
Hovering an enabled button triggers the tooltip

Qt creator - make a dynamic interface

I am working on a small UI with QT Creator and its drag-n'-drop tool (QT Designer). Everything was fine till I realized I had to make some widgets dynamic. For example, I have a checkbox and I want some button to appear only if this checkbox is checked by the user or I would like to change the appearance of another widget when the user clicks on some button.
Is it possible to do it only with QT Designer?
Yes, but it's very limited.
Qt designer have signal&slot editor. Yes, you can connect signal clicked(bool) to setVisible(bool) slot on button and make button visible only when checkbox is checked (see screenshot).
But when You need more complex dynamic interface (e.g. creating buttons), designed will not help You.

Is there a hide property for pushbutton in Qt Creator?

Is there a hide property for pushbutton in Qt Creator property pallet? I am trying to find one but I am not able to find. I need to make some buttons disable & some hide. Should I use property pallet for it OR do it in constructor? Later on user event, they will be enable & shown.
Some controls have "visibility" property on the palette, some don't. You always may do that programmatically (for example in the dialog's constructor):
MyButton->setVisible(false); //or true - later in the code
In old versions of Qt Designer there was a property visible for it. But it seems that it was removed in new versions, so you can't use it directly.
But it is still possible to add this field in the .ui file. Just open any text editor, find the part related to the widget you need to hide, and insert this block in that place:
<property name="visible">
<bool>false</bool>
</property>
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.

Resources