-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpyqt4.py
110 lines (83 loc) · 2.74 KB
/
pyqt4.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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
#! /usr/bin/env python
# -*- coding: utf-8 -*-
#
import sys
from PyQt4.QtGui import *
from PyQt4 import QtGui, QtCore
# Create an PyQT4 application object.
'''
class sub(QtGui.QWidget):
def mousePressEvent(self,event):
print "yes"
QtGui.QWidget.mousePressEvent(self, event)
def __init__(self):
super(sub,self).__init__()
self.label=QLabel()
def Label(self):
return self.label
'''
a = QApplication(sys.argv)
icon=QIcon()
w2=QGridLayout()
container=QWidget()
w=QGridLayout()
scroll=QScrollArea()
def update(position):
label=Newlabel()
label.setPixmap(icon.pixmap(128,QIcon.Selected,QIcon.On))
QtCore.QObject.connect(label, QtCore.SIGNAL('clicked()'), label.lp)
w.addWidget(label,*position)
class Newlabel(QLabel):
position=[]
layout=QGridLayout()
def lp(self):
update(self.position)
def mousePressEvent(self,event):
self.emit(QtCore.SIGNAL('clicked()'))
#QtGui.QWidget.mousePressEvent(self, event)
class Main(QtGui.QMainWindow):
def __init__(self, parent = None):
super(Main, self).__init__(parent)
self.centralWidget=QWidget()
self.setCentralWidget(self.centralWidget)
size=128
mode=QIcon.Normal
state=QIcon.Off
pixma = QPixmap('folder.png')
icon.addPixmap(pixma,mode,state)
positions = [(i,j) for i in range(5) for j in range(4)]
button=QtCore.Qt.LeftButton
event=QtCore.QEvent.MouseButtonPress
#pos1=QMouseEvent.pos()
#m=QMouseEvent()
for position in positions:
h=QVBoxLayout()
label=Newlabel()
txtlabel=QLabel()
txtlabel.setText("Documents")
h.addWidget(txtlabel)
label.position=position
label.setPixmap(icon.pixmap(size,QIcon.Normal,state))
QtCore.QObject.connect(label, QtCore.SIGNAL('clicked()'), label.lp)
w.addWidget(label,*position)
h.addStretch(1)
w.addItem(h,*position)
container.setLayout(w)
scroll.setWidget(container)
w2.addWidget(scroll)
self.centralWidget.setLayout(w2)
self.centralWidget.setMinimumSize(300,300)
# Set window size.
# Set window title
# Add a button
'''
w.addWidget(s,0,0,0)
btn.setToolTip('Click to quit!')
btn.clicked.connect(exit)
btn.resize(btn.sizeHint())
'''
# Show window
if __name__ == "__main__":
q=Main()
q.show()
sys.exit(a.exec_())