Issue
I have group of label and combo box which I need to group. By toggling group name i should able to see the widgets. I have found only checkable in group box widget which is disabling the widgets instead collapsible. How can we achieve this in QT designers.
I want to achive like below in QT designer. Please show some light on this
Solution
This can theoretically be done in Designer, but with the following limitations:
- the widgets should be put in a single container (like a QWidget) that must not be the same as the checkbox;
- alternatively, the connection (see below) should be done individually for each widget;
- widgets cannot be directly hidden in Designer, so if they have to be hidden by default, that must be done by code;
- toggling widgets visibility will alter the layout, which might not be ideal; the alternative is to use
setRetainSizeWhenHidden()
on their size policy, which can only be done by code; - the checkbox does not use an icon, so you need to set a proper stylesheet for it if you want to display an arrow;
The procedure is the following:
- add a QCheckBox to the layout;
- add a QWidget as a container at its bottom;
- add at least one widget to that container, then set a layout for it;
- add the other widgets;
- enter in the "Signal/Slot" mode (F4 or from the "Edit" menu)
- press the mouse button on the checkbox, move the mouse to the container (not the widgets!) and release the mouse button;
- a dialog will open, check the "Show signals and slots inherited from QWidget";
- select the
toggled(bool)
signal on the left; - select the
setVisible(bool)
slot on the right; - click "Ok" to close the dialog;
Note about point 3: adding a layout to a container always requires to add a child widget (Designer doesn't allow to create layouts for empty widgets). In case the container becomes too small to add child widgets before the layout is set, you can temporarily set its minimum height (and/or width, depending on the orientation) in the property box, then remember to reset that property once the layout has been set.
Remember that, in general, aspects like these are normally implemented by code for better control over their behavior.
Answered By - musicamante
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.