English
PySide6-Expand Usage Guide
0. Installation
Install PySide6-Expand using pip:
pip install pyside6-expand
Then import the required module in your code:
from pyside6_expand.expand_signal import mouse_signal
1. Extension - Mouse Signals
Apply the @mouse_signal
decorator to classes that inherit from QWidget
to dynamically bind mouse event signals at runtime.
Supported Signals
left_clicked
: Left button clickleft_double_clicked
: Left button double clickleft_long_press
: Left button long pressright_clicked
: Right button clickright_double_clicked
: Right button double clickright_long_press
: Right button long press
These signals operate independently and do not interfere with each other.
Notes
- The
@mouse_signal
decorator overrides the methodsmouseDoubleClickEvent
,mousePressEvent
, andmouseReleaseEvent
. - When handling mouse press events,
mousePressEvent
is called first, followed by the corresponding signal. - When handling mouse release events,
mouseReleaseEvent
is called first, followed by the logic of the respective signal. - Do not override
mouseDoubleClickEvent
again, otherwise theleft_double_clicked
andright_double_clicked
signals will fail to work.
Example Code
from pyside6_expand.expand_signal import mouse_signal
from PySide6.QtWidgets import QWidget, QApplication
@mouse_signal
class CustomWidget(QWidget):
def __init__(self):
super().__init__()
if __name__ == '__main__':
app = QApplication([])
widget = CustomWidget()
# Connect signals to slots
widget.left_clicked.connect(lambda: print("Left button clicked"))
widget.left_double_clicked.connect(lambda: print("Left button double clicked"))
widget.left_long_press.connect(lambda: print("Left button long pressed"))
widget.right_clicked.connect(lambda: print("Right button clicked"))
widget.right_double_clicked.connect(lambda: print("Right button double clicked"))
widget.right_long_press.connect(lambda: print("Right button long pressed"))
widget.show()
app.exec()
Additional Features
This project is actively developing new features, so stay tuned for updates.