-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhighlightable.py
More file actions
29 lines (25 loc) · 1.07 KB
/
highlightable.py
File metadata and controls
29 lines (25 loc) · 1.07 KB
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
from PySide6.QtWidgets import QFrame, QVBoxLayout
from PySide6.QtCore import Qt
class HighlightableWidget(QFrame):
'''A widget that changes color when hovered.'''
def __init__(self, background, selected, hover):
'''Accepts a `background` and `hover` color (#ABABAB)'''
super().__init__()
self.setLayout(QVBoxLayout())
self.layout().setContentsMargins(0, 0, 0, 0)
self.layout().setSpacing(5)
self.background = background
self.selected = selected
self.hover = hover
self.setStyleSheet(f'background-color: {self.background}')
def enterEvent(self, event):
self.setStyleSheet(f'background-color: {self.background}')
super().enterEvent(event)
def mousePressEvent(self, event):
if event.button() == Qt.LeftButton:
self.isSelected = True
self.setStyleSheet(f'background-color: {self.selected}')
super().mousePressEvent(event)
def leaveEvent(self, event):
self.setStyleSheet(f'background-color: {self.background}')
super().leaveEvent(event)