我真正想做的是告诉它在调用 setVisible(true) 或 setVisible(false) 时不要移动东西。我该怎么做?
最佳答案
使用QSizePolicy::setRetainSizeWhenHidden
:
void QSizePolicy::setRetainSizeWhenHidden(bool retainSize)
Sets whether a layout should retain the widget's size when it is hidden. If retainSize is true, the layout will not be changed by hiding the widget.
换句话说:
QSizePolicy p = widget->sizePolicy();
p.setRetainSizeWhenHidden(true);
widget->setSizePolicy(p);
关于c++ - 在 Qt 中,在使用 hide() 或 setVisible(false) 时,如何阻止子网格布局尝试将所有内容居中?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38424238/