PySide6-Expand Usage Guide

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 click
  • left_double_clicked: Left button double click
  • left_long_press: Left button long press
  • right_clicked: Right button click
  • right_double_clicked: Right button double click
  • right_long_press: Right button long press

These signals operate independently and do not interfere with each other.

Notes

  • The @mouse_signal decorator overrides the methods mouseDoubleClickEvent, mousePressEvent, and mouseReleaseEvent.
  • 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 the left_double_clicked and right_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.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值