python - PySide metro style mousepressevent -


i trying have python desktop application metro (windows 8) style, table of rectangles can clicked something.

i generate table of rectangles (myicon) this:

for sub_rectx in xrange(4):     sub_recty in xrange(3):         tmp = myicon(sub_rectx*322, sub_recty*192, 300, 170, sub_recty+3*sub_rectx + 1, parent=parent) 

and have class, rectangle id:

class myicon(mypanel):     def __init__(self, x, y, width, height, ide, parent=none):         super(mypanel, self).__init__(parent)         qtgui.qgraphicsrectitem.__init__(self, x, y, width, height, parent)         self.ide = ide      def mousepressevent(self, event):         self.setbrush(qtgui.qcolor(255, 255, 255))         print self.ide 

this code works fine first time click on rectangle, printing correct id, , changing colour of correct rectangle, next times click on rectangle it's printing id of first rectangle clicked , colour not changed (i assume because it's painting again same rectangle well).

can me?

i see 2 issues:

1) when call super(..) have pass current class first parameter (myicon , not mypanel). pass proper parameters, , don't call init function of qgraphicsrectitem there (your parent class it).

2) in mouse event handler, should call super function too:

super(myicon, self).mousepressevent(event)

this should solve issue.


Comments

Popular posts from this blog

css - Which browser returns the correct result for getBoundingClientRect of an SVG element? -

gcc - Calling fftR4() in c from assembly -

.htaccess - Matching full URL in RewriteCond -