-
Notifications
You must be signed in to change notification settings - Fork 0
/
stackoverflow3.py
47 lines (33 loc) · 1.23 KB
/
stackoverflow3.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
43
44
45
46
47
# -*- coding: utf-8 -*-
from PySide import QtGui, QtCore
class MainWindow(QtGui.QWidget):
'''Main window lets user know when window was clicked on non-widget space'''
def __init__(self):
QtGui.QWidget.__init__(self)
self.initUI()
def initUI(self):
self.myLabel = TalkingQLabel("Don't mess with Breakfast!", self)
self.myLabel.setGeometry(50, 50, 200, 120)
self.setGeometry(300, 200, 300, 250)
self.show()
def mousePressEvent(self, event):
print
"Well, you pressed in main window!"
class TalkingQLabel(QtGui.QLabel):
'''QLab el that indicates when it was pressed'''
def __init__(self, txt, parent):
QtGui.QLabel.__init__(self, txt, parent)
self.initUI()
def initUI(self):
self.setAlignment(QtCore.Qt.AlignCenter)
self.setStyleSheet("QLabel { color: rgb(255, 255, 0); font-size: 15px; background-color: rgb(0,0,0)}")
def mousePressEvent(self, event):
print
"This time you pressed in a label"
def main():
import sys
qtApp = QtGui.QApplication(sys.argv)
myTalker = MainWindow()
sys.exit(qtApp.exec_())
if __name__ == "__main__":
main()