开发者

Lining up Qt GroupBox labels

Is there an easy way to ensure that controls in different groupboxes on a Qt dialog line up correctly using layouts? If not, is there a way to line them up using code in the dialog's constructor?

For example, here is a form with two groupboxes containing controls that are laid out using a grid:

alt text http://lh3.ggpht.com/_4pUyapZ-mEE/S4w93l4Ab5I/AAAAAAAACQE/mJraY0z1jyI/groupbox1.png

Here is how I want it to look:

alt text http://lh5.ggpht.com/_4pUyapZ-mEE/S4w93rKiEBI/AAAAAAAACQI/nlt7mul79p8/groupbox2.png

Note that these dialogs will end up translated into different languages so what 开发者_JS百科might be the longest label in English won't necessarily be the same label in German.


I don't think there is an easy solution since you have to separated and not connected layouts. What you could do is after you set up the layouts is iterating over all label strings and measure their size with QWidget::fontMetrics() on their label widget, remeber the maximum value and call QWidget::setMinimumWidth(). That you can also do after translating strings (if you do it dynamically at run-time).

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜