【问题标题】:How to set QPushButton stylesheet affecting buttons size?如何设置影响按钮大小的 QPushButton 样式表?
【发布时间】:2013-10-23 12:40:49
【问题描述】:

当我使用以下样式表进行 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 上尝试的任何其他样式表相同。如何在不影响默认大小的情况下设置按钮样式表?

【问题讨论】:

    标签: qt stylesheet qpushbutton qtstylesheets


    【解决方案1】:

    我认为你不能在不影响小部件默认大小的情况下弄乱边框或填充。你可以设置min-width

    来自文档:If this property is not specified, the minimum width is derived based on the widget's contents and the style.

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-02-01
      • 2012-08-17
      • 2014-03-14
      • 2012-06-15
      • 1970-01-01
      • 2023-03-21
      相关资源
      最近更新 更多