[PyKDE] Method returning a QObject instance instead of QHeader

Phil Thompson phil at riverbankcomputing.co.uk
Thu Jan 13 10:11:36 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?

Jim's explanation of the problem is correct. The reason why your use of
unwrapinstance() and wrapinstance() doesn't work is, as the documentation
says, wrapinstance() will return a new reference to an existing object if
it has already been wrapped.

What I will do is change sip.cast() so that the type argument doesn't have
to be a super-class of the existing type of the object - ie. you will be
able to cast anything to anything and will always get a new object of the
required type. The change should be in the next snapshot.

Phil




More information about the PyQt mailing list