-
Notifications
You must be signed in to change notification settings - Fork 0
/
hover_test_stylesheet.py
38 lines (28 loc) · 1.21 KB
/
hover_test_stylesheet.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
from PySide2 import QtCore, QtGui, QtWidgets
STYLE_HOVER = 'QCheckBox {background: rgba(255, 0, 0, 125);} QCheckBox:hover {background: red;}'
STYLE_NONE = 'QCheckBox {background: transparent} QCheckBox:hover {background: red;}'
class Widget(QtWidgets.QWidget):
def __init__(self):
super(Widget, self).__init__()
layout = QtWidgets.QVBoxLayout(self)
blank = QtWidgets.QLabel('Thanks <b>dbunk</b>!! 🙏')
blank.setFont(QtGui.QFont('', 40))
blank.setMinimumSize(500, 200)
layout.addWidget(blank)
self.check = QtWidgets.QCheckBox('i wanna be hovered!')
layout.addWidget(self.check)
self.check.setStyleSheet(STYLE_NONE)
def mousePressEvent(self, event: QtGui.QMouseEvent) -> None:
self.check.toggle()
return super().mousePressEvent(event)
def enterEvent(self, event: QtCore.QEvent) -> None:
self.check.setStyleSheet(STYLE_HOVER)
return super().enterEvent(event)
def leaveEvent(self, event: QtCore.QEvent) -> None:
self.check.setStyleSheet(STYLE_NONE)
return super().leaveEvent(event)
if __name__ == '__main__':
app = QtWidgets.QApplication([])
main = Widget()
main.show()
app.exec_()