将小部件放置在QScrollArea的中心 [英] Place widget in center of QScrollArea
问题描述
如何将尺寸固定的自定义小部件放置在QScrollArea的中心?
How can I place custom widget with fixed size in center of QScrollArea?
我可以使用myWidget.pos(x,y)将小部件手动放置在QScrollArea内,但是QScrollArea中没有sizeChanged信号,因此如果滚动区域更改,此位置将是错误的.
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.
推荐答案
我使用@thuga的建议来设置对齐方式,但是我还必须为小部件设置一个固定的大小(在此之前,我仅设置了最小大小),而且我还需要使用水平布局而不是垂直布局.由于某些原因,垂直布局会忽略滚动区域的水平对齐方式.
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. For some reason, the vertical layout disregards the scroll area's horizontal alignment.
我使用 setFixedSize()
为自定义窗口小部件设置了固定大小,但是可以从Qt Designer中设置布局和对齐方式.
I used setFixedSize()
to set a fixed size for my custom widget, but the layout and the alignment can be set from Qt Designer.
这篇关于将小部件放置在QScrollArea的中心的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!