【问题标题】:QPushButton dimensions change when Stylesheet is apllied应用样式表时 QPushButton 尺寸发生变化
【发布时间】:2015-04-29 10:58:19
【问题描述】:

当我在 QPushButton 上应用样式表时,它的尺寸会发生变化。 这是我的样式表声明。

 QPushButton { 
   background-color: rgb(175, 187, 199);
   color: black;
   border-width: 1px;
   border-top: 1px solid white;
   border-left: 1px solid white;
   border-right: 1px solid grey;
   border-bottom: 1px solid grey;
   border-style: solid;
   border-radius: 5;
   padding: 3px; 
   padding-left: 5px; 
   padding-right: 5px;
   font: 16px;
   font-weight: bold;
}

Image - Before applying style sheet

Image - After applying style sheet

如何保持原来的按钮大小?

【问题讨论】:

  • 您可以在样式表中添加min-width
  • 最小宽度影响所有按钮:(
  • 这个样式表应该影响所有按钮,所以......?也许您应该在样式表中添加一些限定条件?
  • @MarekR 我创建的对话框中的 QPushButtons 是可能的,但是我不知道如何为 QMessageBox 中的按钮执行此操作。有什么想法吗?
  • 是的,有可能,看我的回答。

标签: qt qt4 stylesheet qtstylesheets qpushbutton


【解决方案1】:

基于以下问题的评论:尝试添加限定符:

MyDialog QPushButton { 
   background-color: rgb(175, 187, 199);
   color: black;
   border-width: 1px;
   border-top: 1px solid white;
   border-left: 1px solid white;
   border-right: 1px solid grey;
   border-bottom: 1px solid grey;
   border-style: solid;
   border-radius: 5;
   padding: 3px; 
   padding-left: 5px; 
   padding-right: 5px;
   font: 16px;
   font-weight: bold;
}

这应该与默认样式表合并(而不是覆盖整个东西),并且只适用于您需要更改的按钮。

documentation

【讨论】:

    猜你喜欢
    • 2020-11-06
    • 1970-01-01
    • 2020-03-27
    • 2021-04-20
    • 2021-10-02
    • 2022-07-08
    • 2019-08-16
    • 1970-01-01
    • 2022-09-24
    相关资源
    最近更新 更多