when I create a QHBoxLayout
and I add widgets in it with addWidget
and then call myLayout->setAlignment(newWidget, Qt::AlignLeft)
, this only snaps the first widget I add. When I add other widgets and set their alignment to left too, they still start off at the center of the layout and then get squeezed in the more widgets I add. How do I make them all stick to the left next to each other?
If I understood it correct, what you want is to have your widgets in a horizontal line but as left as possible?
If so you can add your QHBoxLayot to the general this->getLayout()->addLayout(YourLayout)
and then use setContentMargins();
or setStretchFactor(QWidget * widget, int stretch)
Without the code is difficult but ... Another possible problem can be the widgets size. You can fix it using setSizePolicy(...)
with the MinimumExpanding setSizePolicy( QSizePolicy::MinimumExpanding, QSizePolicy::Preferred );
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.