[PyQt] How to handle sip_voidptr

Burak Nehbit burak at nehbit.net
Sat Nov 9 03:48:01 GMT 2013


Hi,

I’m trying to get Qt’s native events support working in PyQt.

As per this documentation: http://qt-project.org/doc/qt-5.0/qtcore/qabstractnativeeventfilter.html 

I wrote the following code:

class MacEventFilter(QtCore.QAbstractNativeEventFilter):
    def __init__(self):
        super(MacEventFilter, self).__init__()

    def nativeEventFilter(self, QByteArray, sip_voidptr):
        sip_voidptr.setsize(4) #32 bit (?)
        cobject = sip_voidptr.ascobject()
        print(repr(cobject))
        #cp = cast(sip_voidptr.asstring(), POINTER(c_void_p))
        print(cp.contents)
        return True

mef = MacEventFilter()
app.installNativeEventFilter(mef)

The problem I am having is I do not know know to deal with sip_voidptr. The documentation casts this into … something, and continues to use it. I’m working on a Mac application, so in that case it seems I have to cast this into an EventRef. 

The sole documentation I can find about EventRef is this: http://oreilly.com/catalog/learncarbon/chapter/ch06.html#CHAP-CH06-6

Is this already a SIP, Qt or PyQt object? How can I cast this? Python does not do casting to classes(structs?), so there must be some way in SIP to handle this. But I do not know where to start looking or what is it called. 

After I cast this, I will (hopefully) have an event object that can give me information about the event.

My ultimate purpose is to be aware when my user clicks the dock icon on Mac. Clicking on the dock icon should draw the UI if it is closed, and bring the UI to the front if it is open but in the background. Qt unfortunately does not offer a native way to handle click to the dock icon.

Any pointers on where to start?

Regards,
Burak
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.riverbankcomputing.com/pipermail/pyqt/attachments/20131108/deffd11f/attachment.html>


More information about the PyQt mailing list