[英]QHBoxLayout widget alignment only affects first widget
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. 当我创建QHBoxLayout
并使用addWidget
在其中添加小部件,然后调用myLayout->setAlignment(newWidget, Qt::AlignLeft)
,这只会捕捉我添加的第一myLayout->setAlignment(newWidget, Qt::AlignLeft)
部件。 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();
如果是这样,您可以将QHBoxLayot添加到常规this->getLayout()->addLayout(YourLayout)
,然后使用setContentMargins();
this->getLayout()->addLayout(YourLayout)
or setStretchFactor(QWidget * widget, int stretch)
或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 );
您可以将setSizePolicy(...)
与MinimumExpanding setSizePolicy( QSizePolicy::MinimumExpanding, QSizePolicy::Preferred );
一起使用进行修复setSizePolicy( QSizePolicy::MinimumExpanding, QSizePolicy::Preferred );
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.