简体   繁体   English

将小部件放在QScrollArea的中心

[英]Place widget in center of QScrollArea

How can I place custom widget with fixed size in center of QScrollArea? 如何将固定大小的自定义小部件放在QScrollArea的中心?

I can place the widget manually inside QScrollArea with myWidget.pos(x,y) but there is no sizeChanged signal in QScrollArea so this position will be wrong if scroll area changed. 我可以使用myWidget.pos(x,y)在QScrollArea中手动放置窗口小部件,但QScrollArea中没有sizeChanged信号,因此如果滚动区域更改,此位置将是错误的。

I used @thuga's suggestion to set the alignment, but additionally I had to set a fixed size for the widget (I was settings only the minimum size before that), and also I needed to use a horizontal layout instead of a vertical one. 我使用@ thuga的建议来设置对齐,但另外我必须为窗口小部件设置固定大小(我之前只设置了最小尺寸),而且我还需要使用水平布局而不是垂直布局。 For some reason, the vertical layout disregards the scroll area's horizontal alignment. 出于某种原因, 垂直布局忽略了滚动区域的水平对齐。

I used setFixedSize() to set a fixed size for my custom widget, but the layout and the alignment can be set from Qt Designer. 我使用setFixedSize()为我的自定义小部件设置固定大小,但可以从Qt Designer设置布局和对齐方式。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM