如何设置QPushButton的样式表以影响按钮的大小?

4
当我使用以下样式表调用QApplication::setStyleSheet()函数时:
QPushButton {
    border-radius: 2px;
    padding: 0.2em 0.2em 0.3em 0.2em;
    border: 1px solid rgb(100, 100, 100);
    background: qlineargradient(x1:0, y1:0, x2:0, y2:1,
                                  stop:0 #f4f4f4, stop:0.1 #8F8F8F, stop:1  #7B7B7B);
    color: white;
}

所有按钮的大小都被截断为文本的大小。例如,确定按钮变成了正方形。我在QPushButton上尝试了任何其他样式表都会产生相同的效果。如何在不影响其默认大小的情况下设置按钮样式表?
1个回答

5

我认为如果你调整边框或填充,就会影响小部件的默认大小。但是,您可以设置最小宽度

来自文档:如果未指定此属性,则根据小部件内容和样式派生出最小宽度。

QPushButton {
    border-radius: 2px;
    padding: 0.2em 0.2em 0.3em 0.2em;
    border: 1px solid rgb(100, 100, 100);
    background: qlineargradient(x1:0, y1:0, x2:0, y2:1,
                                  stop:0 #f4f4f4, stop:0.1 #8F8F8F, stop:1  #7B7B7B);
    color: white;
    min-width: 70px;
}

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接