开发者

Ignore minimum size when resizing QWidget

开发者 https://www.devze.com 2023-04-08 14:13 出处:网络
Is there a way to make a QWidget (and any subclass of it) completely ignore its minimum size? 开发者_运维百科What I want is for a QPushButton to cut off when it is sized too small, rather than prevent

Is there a way to make a QWidget (and any subclass of it) completely ignore its minimum size? 开发者_运维百科What I want is for a QPushButton to cut off when it is sized too small, rather than prevent the window from resizing (the default behavior).


You can use:

button.setSizePolicy(QSizePolicy.Ignored, QSizePolicy.Ignored)

but you'll have to set the initial size yourself.
Or you can just set the minimum size to a small non-zero value:

button.setMinimumSize(1,1)

To apply that to all buttons within a widget, you could try to use a style sheet, but the borders don't disappear when the button is at its minimum content size (at least with QGtkStyle on Linux):

dialog.setStyleSheet("QPushButton { min-height: 0px; min-width: 0px }");
0

精彩评论

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

关注公众号