created clickable label in utils

This commit is contained in:
Jakub Trllo 2022-02-21 16:51:30 +01:00
parent b7f6e2dd55
commit 42f47c868b
2 changed files with 28 additions and 1 deletions

View file

@ -2,11 +2,12 @@ from .widgets import (
PlaceholderLineEdit,
BaseClickableFrame,
ClickableFrame,
ClickableLabel,
ExpandBtn,
PixmapLabel,
IconButton,
)
from .views import DeselectableTreeView
from .error_dialog import ErrorMessageBox
from .lib import (
WrappedCallbackItem,
@ -24,10 +25,13 @@ __all__ = (
"PlaceholderLineEdit",
"BaseClickableFrame",
"ClickableFrame",
"ClickableLabel",
"ExpandBtn",
"PixmapLabel",
"IconButton",
"DeselectableTreeView",
"ErrorMessageBox",
"WrappedCallbackItem",

View file

@ -63,6 +63,29 @@ class ClickableFrame(BaseClickableFrame):
self.clicked.emit()
class ClickableLabel(QtWidgets.QLabel):
"""Label that catch left mouse click and can trigger 'clicked' signal."""
clicked = QtCore.Signal()
def __init__(self, parent):
super(ClickableLabel, self).__init__(parent)
self._mouse_pressed = False
def mousePressEvent(self, event):
if event.button() == QtCore.Qt.LeftButton:
self._mouse_pressed = True
super(ClickableLabel, self).mousePressEvent(event)
def mouseReleaseEvent(self, event):
if self._mouse_pressed:
self._mouse_pressed = False
if self.rect().contains(event.pos()):
self.clicked.emit()
super(ClickableLabel, self).mouseReleaseEvent(event)
class ExpandBtnLabel(QtWidgets.QLabel):
"""Label showing expand icon meant for ExpandBtn."""
def __init__(self, parent):