Add mouse events
This commit is contained in:
parent
5963d88966
commit
56fdcd9114
1 changed files with 36 additions and 1 deletions
|
|
@ -1,6 +1,6 @@
|
|||
import sys
|
||||
|
||||
from PySide6.QtCore import QSize
|
||||
from PySide6.QtCore import Qt, QSize
|
||||
from PySide6.QtWidgets import (
|
||||
QApplication,
|
||||
QLabel,
|
||||
|
|
@ -20,6 +20,7 @@ class leekMainWindow(QMainWindow):
|
|||
self.setWindowTitle("Leek!")
|
||||
|
||||
self.label = QLabel()
|
||||
self.mouse_label = QLabel()
|
||||
|
||||
self.input = QLineEdit()
|
||||
self.input.textChanged.connect(self.label.setText)
|
||||
|
|
@ -32,6 +33,7 @@ class leekMainWindow(QMainWindow):
|
|||
layout = QVBoxLayout()
|
||||
layout.addWidget(self.input)
|
||||
layout.addWidget(self.label)
|
||||
layout.addWidget(self.mouse_label)
|
||||
layout.addWidget(button)
|
||||
|
||||
self.setMaximumSize(QSize(800, 600))
|
||||
|
|
@ -49,6 +51,39 @@ class leekMainWindow(QMainWindow):
|
|||
def button_toggled(self, checked):
|
||||
print("Checked?", checked)
|
||||
|
||||
def mouseMoveEvent(self, e):
|
||||
self.mouse_label.setText("mouseMoveEvent")
|
||||
|
||||
def mousePressEvent(self, e):
|
||||
button = ""
|
||||
if e.button() == Qt.MouseButton.LeftButton:
|
||||
button = "left"
|
||||
elif e.button() == Qt.MouseButton.MiddleButton:
|
||||
button = "middle"
|
||||
elif e.button() == Qt.MouseButton.RightButton:
|
||||
button = "right"
|
||||
self.mouse_label.setText("mousePressEvent " + button)
|
||||
|
||||
def mouseReleaseEvent(self, e):
|
||||
button = ""
|
||||
if e.button() == Qt.MouseButton.LeftButton:
|
||||
button = "left"
|
||||
elif e.button() == Qt.MouseButton.MiddleButton:
|
||||
button = "middle"
|
||||
elif e.button() == Qt.MouseButton.RightButton:
|
||||
button = "right"
|
||||
self.mouse_label.setText("mouseReleaseEvent " + button)
|
||||
|
||||
def mouseDoubleClickEvent(self, e):
|
||||
button = ""
|
||||
if e.button() == Qt.MouseButton.LeftButton:
|
||||
button = "left"
|
||||
elif e.button() == Qt.MouseButton.MiddleButton:
|
||||
button = "middle"
|
||||
elif e.button() == Qt.MouseButton.RightButton:
|
||||
button = "right"
|
||||
self.mouse_label.setText("mouseDoubleClickEvent " + button)
|
||||
|
||||
|
||||
def main():
|
||||
# If you know you won't use command line arguments QApplication([]) works too.
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue