[prev in list] [next in list] [prev in thread] [next in thread]
List: pykde
Subject: [PyKDE] Re: How can I prevent a QLable from eating MouseEvents?
From: "Markus Gritsch" <gritsch () iue ! tuwien ! ac ! at>
Date: 2001-05-26 14:52:51
[Download RAW message or body]
Hi!
I have found a solution by installing an EventFilter:
import sys
from qt import *
class MyEventFilter(QObject):
def __init__(self, parent):
QObject.__init__(self, parent)
self.parent = parent
def eventFilter(self, object, event):
if event.type() == QEvent.MouseButtonPress:
print 'click'
return 1
return 0
class Form1(QDialog):
def __init__(self, parent=None, name='Form1', modal=0, fl = 0):
QDialog.__init__(self,parent,name,modal,fl)
self.resize(120,60)
self.setCaption(self.tr('Form1'))
self.TextLabel1 = QLabel(self, 'TextLabel1')
self.TextLabel1.setGeometry(QRect(30,20,61,15))
self.TextLabel1.setText('TextLabel1')
self.myeventfilter = MyEventFilter(self)
self.installEventFilter(self.myeventfilter)
self.TextLabel1.installEventFilter(self.myeventfilter)
a = QApplication(sys.argv)
QObject.connect(a,SIGNAL('lastWindowClosed()'),a,SLOT('quit()'))
w = Form1()
a.setMainWidget(w)
w.show()
a.exec_loop()
> How can I prevent a QLable from eating MouseEvents? If I click
> outside the lable in the following example, mousePressEvent() is
> called, if I click on the lable it is not. What can I do to receive
> MouseEvents in any case?
>
>
> import sys
> from qt import *
>
> class Form1(QDialog):
> def __init__(self, parent=None, name='Form1', modal=0, fl = 0):
> QDialog.__init__(self,parent,name,modal,fl)
>
> self.resize(120,60)
> self.setCaption(self.tr('Form1'))
>
> self.TextLabel1 = QLabel(self, 'TextLabel1')
> self.TextLabel1.setGeometry(QRect(30,20,61,15))
> self.TextLabel1.setText('TextLabel1')
>
> def mousePressEvent(self, mouseEvent):
> print 'click'
>
> if __name__ == '__main__':
> a = QApplication(sys.argv)
> QObject.connect(a,SIGNAL('lastWindowClosed()'),a,SLOT('quit()'))
> w = Form1()
> a.setMainWidget(w)
> w.show()
> a.exec_loop()
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic