[PyKDE] Method returning a QObject instance instead of QHeader
Bruno da Silva de Oliveira
bruno at esss.com.br
Wed Jan 12 20:47:15 GMT 2005
Hi everyone,
I'm having a problem that I hope someone can provide an answer.
I'm subclassing QTable, and I install an event filter in its vertical
QHeader instance. When I catch a mouse double click event inside the
event filter, destined to the header, any calls inside the event filter
to the QTable's method verticalHeader() returns an instance of QObject,
instead of QHeader.
Attached is a simple example (40 lines) that demonstrates the problem.
Note that calling verticalHeader() in __init__() returns a QHeader
object as expected, but when called from inside the eventFilter() method
it returns a QObject instance.
I tried to force the QObject returned from verticalHeader() to become a
QHeader by using calls to sip.unwrapinstance/sip.wrapinstance (as shown
in the code), but without success.
Anyone has any idea of what the problem may be? Any workarounds?
Best Regards,
--
Bruno da Silva de Oliveira
bruno at esss.com.br
ESSS - Engineering Simulation and Scientific Software
http://www.esss.com.br
-------------- next part --------------
from qt import *
from qttable import QTable, QTableSelection
import sip
#================================================================================
# MyTable
#================================================================================
class MyTable(QTable):
def __init__(self, *args):
QTable.__init__(self, *args)
self.setColumnMovingEnabled(True)
self.setRowMovingEnabled(True)
self.verticalHeader().installEventFilter(self)
self.horizontalHeader().installEventFilter(self)
header = self.verticalHeader()
print 'OnInit:', header, self
def eventFilter(self, obj, event):
if obj is self.verticalHeader():
if event.type() == QEvent.MouseButtonDblClick:
header = self.verticalHeader()
print 'OnEventFilter:', header, self
x = sip.unwrapinstance(header)
o = sip.wrapinstance(x, QHeader)
print 'sip.wrapinstance:', o
return QTable.eventFilter(self, obj, event)
if __name__ == '__main__':
app = QApplication([])
win = MyTable(3, 3)
win.show()
app.setMainWidget(win)
app.exec_loop()
More information about the PyQt
mailing list