调整 QWidget 时忽略最小尺寸 [英] Ignore minimum size when resizing QWidget

查看:110
本文介绍了调整 QWidget 时忽略最小尺寸的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有办法让 QWidget(以及它的任何子类)完全忽略它的最小尺寸?我想要的是当 QPushButton 的尺寸太小时切断它,而不是阻止窗口调整大小(默认行为).

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).

推荐答案

您可以使用:

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)

要将其应用于小部件中的所有按钮,您可以尝试使用样式表,但是当按钮处于其最小内容大小时,边框不会消失(至少使用 QGtkStyle在 Linux 上):

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 }");

这篇关于调整 QWidget 时忽略最小尺寸的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆