如何使已检查的QPushButton看起来像按下时一样?

时间:2016-09-21 12:52:29

标签: qt checked qtstylesheets qpushbutton

如何使已检查的QPushButton看起来与按下时相同?像这样:

enter image description here

这是按下按钮的图片。我应该在样式表中写什么?

"QPushButton:pressed {"
 "background-color: qlineargradient(x1: 0, y1: 0, x2: 0, y2: 1,"
                                       "stop: 0 #dadbde, stop: 1 #f6f7fa);}"  
"QPushButton:checked {"
 "background-color: qlineargradient(x1: 0, y1: 0, x2: 0, y2: 1,"
                                   "stop: 0 #dadbde, stop: 1 #f6f7fa);"
 "border: none;}"

我试图将border写为none,但我得到了这个:

enter image description here

我需要保持相同的边界。

1 个答案:

答案 0 :(得分:0)

这是因为在默认情况下QPushButton:被压缩有自己的边框,这是根据您的操作系统本地设置的。

要解决此问题,您可以将QPushButton:按下的边框设置为与现在看起来非常相似的边框,然后为QPushButton设置相同的边框:选中。

在我看来,这是一个1px宽的黑色嵌入式边框,所以这样的事情应该可以解决问题。

"QPushButton:pressed {"
"background-color: qlineargradient(x1: 0, y1: 0, x2: 0, y2: 1,"
                                       "stop: 0 #dadbde, stop: 1 #f6f7fa);" 
"border: 1px inset black;}" 

"QPushButton:checked {"
 "background-color: qlineargradient(x1: 0, y1: 0, x2: 0, y2: 1,"
                                   "stop: 0 #dadbde, stop: 1 #f6f7fa);"
 "border: 1px inset black;}"