QPushButton:hover
时间: 2023-06-22 07:31:24 浏览: 60
`QPushButton:hover` 是 QPushButton 的 QSS 伪状态之一,表示鼠标悬停在按钮上时的样式。可以使用它来设置按钮的鼠标悬停时的外观效果,例如改变按钮的背景色、文本颜色等。以下是一个示例:
```python
button.setStyleSheet('''
QPushButton {
background-color: #4CAF50;
color: white;
font-size: 20px;
border-radius: 10px;
}
QPushButton:hover {
background-color: #3e8e41;
}
''')
```
上面的代码设置了一个绿色的按钮,当鼠标悬停在按钮上时,按钮的背景色会变成深绿色。
相关问题
QPushButton:hover{background-color: rgb(2,110,180);
QPushButton:hover{background-color: rgb(2,110,180);}是一条CSS样式表规则,用于设置鼠标悬停在QPushButton按钮控件上时的背景颜色。其中:hover表示鼠标悬停状态,background-color表示背景颜色属性,rgb(2,110,180)表示颜色值为RGB模式下的(2,110,180)。这条规则的作用是:当鼠标悬停在QPushButton按钮上时,将按钮的背景颜色设置为RGB模式下的(2,110,180),从而实现按钮的交互效果。我们可以将这条规则应用到QPushButton控件的样式表中,例如:
```
QPushButton {
background-color: gray;
}
QPushButton:hover {
background-color: rgb(2,110,180);
}
```
这样就将QPushButton控件的默认背景颜色设置为灰色,当鼠标悬停在按钮上时,将背景颜色设置为RGB模式下的(2,110,180)。
QPushButton:hover:!pressed { color: blue; }说明
这是一段CSS伪类选择器的语法,它表示当鼠标悬停在QPushButton控件上且该控件没有被按下时,文本颜色将被设置为蓝色。
具体解释如下:
- QPushButton:hover 表示当鼠标悬停在QPushButton控件上时应用此样式。
- :!pressed 表示当QPushButton控件没有被按下时应用此样式。
- { color: blue; } 表示应用的样式,即将文本颜色设置为蓝色。
因此,这段CSS语法的作用是使未被按下的QPushButton控件在鼠标悬停时文本颜色变为蓝色。