-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathevents.py
42 lines (27 loc) · 981 Bytes
/
events.py
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
30
31
32
33
34
35
36
37
38
39
40
41
42
from PySide2 import QtWidgets as qtw
from PySide2 import QtGui as qtg
class MyLineEdit(qtw.QLineEdit):
def __init__(self):
super(MyLineEdit, self).__init__()
def enterEvent(self, event):
self.setText('mouse is in')
def leaveEvent(self, event):
self.setText('mouse is out')
class Panel(qtw.QWidget):
def __init__(self):
super(Panel, self).__init__()
self.label = qtw.QLabel('Click me')
# Add a custom linedit with a custom event handler
self.line_edit = MyLineEdit()
self.main_layout = qtw.QHBoxLayout()
self.main_layout.addWidget(self.label)
self.main_layout.addWidget(self.line_edit)
self.setLayout(self.main_layout)
def mousePressEvent(self, event):
self.label.setText('{}, {}'.format(event.pos().x(), event.pos().y()))
def keyPressEvent(self, event):
print event.text()
app = qtw.QApplication()
panel = Panel()
panel.show()
app.exec_()