[PyKDE] Method returning a QObject instance instead of QHeader

Jim Bublitz jbublitz at nwinternet.com
Thu Jan 13 07:27:14 GMT 2005


On Wednesday 12 January 2005 12:47, Bruno da Silva de Oliveira wrote:
> 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?

The workarounds are fairly easy: in your example, in __init__ change header to 
self.header (or use self.vertHeader and self.horizHeader) so that you don't 
need to get the header object in the eventFilter; alternatively, the 'obj' 
argument passed in to eventFilter is correctly typed as QHeader. You can use 
QHeader.orientation() to determine which header triggered the eventFilter 
call.

Qt doesn't allow you to set the headers to arbitrary objects, so it appears 
event filters are the only method available (the clicked() signal doesn't 
look capable of differentiating between single- and double-clicks easily).

The QTable.verticalHeader () call simply returns (QHeader*)QTable.leftHeader. 
The type of leftHeader (private) is QTableHeader.  QTableHeader is internal 
to QTable (I believe it's declared in the qtable.cpp), so it isn't possible 
to do a sip binding for QTableHeader itself and sip is unaware of that type. 
I would guess something in that construction is causing problems for sip's 
"typecasting" code, but I don't know why it works in __init__ and not 
eventFilter (and why obj is correctly typed). 

Phil, of course, knows the answer.

Jim




More information about the PyQt mailing list