How to group two widgets so that they look like one widget?
Unsolved
General and Desktop
-
I need to display rich text on a checkbox. I tried grouping a QCheckBox and QLabel in a QHBoxLayout. The problem is that it doesn't look like one widget.
struct CheckBox : QWidget{ QHBoxLayout layout{this}; QCheckBox checkbox; QLabel label; CheckBox(){ layout.addWidget(&checkbox); layout.addWidget(&label); // layout.addStretch(); } };
If no stretch is added and the group has a large width, there will be a large space between the checkbox and label.
If a stretch is added after the label, other widgets cannot be added close next to the group.How to group the two widgets so that they look like one widget?
-
@mpergand Thanks. Here's the code that works in my case:
CheckBox(){ layout.addWidget(&checkbox); layout.setAlignment(&checkbox, Qt::AlignRight); layout.addWidget(&label); layout.setAlignment(&label, Qt::AlignLeft); }
-
@mpergand said in How to group two widgets so that they look like one widget?:
And create your objects dynamically (with new), i'm suprised this doesn't crash !
Still suggest you follow @mpergand's advice for this, for safety.
1/4