[PyQt] Type casting

Rendezvous junk_and_mail at yahoo.com
Tue Mar 31 19:39:56 BST 2009

I am using Qt4.5 and PyQt4 and i have subclassed a QWebView with a custom contextMenuEvent, and one of the actions of the menu contains the URL of the link that the action was called for. Without having to perhaps subclass QAction, i use QObject.sender() in attempt to retrieve the QAction that was clicked on. However, i get an AttributeError, that there is no attribute called data, where there would have been had it been a QAction. Unless there's another way of achieving what i want without perhaps subclassing QAction (i.e. if subclassing would indeed help), then knowing how to type cast a QObject to a QAction would be very helpful for my purpose.

--- On Tue, 3/31/09, Phil Thompson <phil at riverbankcomputing.com> wrote:

> From: Phil Thompson <phil at riverbankcomputing.com>
> Subject: Re: [PyQt] Type casting
> To: "Rendezvous" <junk_and_mail at yahoo.com>
> Cc: pyqt at riverbankcomputing.com
> Date: Tuesday, March 31, 2009, 11:09 AM
> On Tue, 31 Mar 2009 07:49:00 -0700
> (PDT), Rendezvous
> <junk_and_mail at yahoo.com>
> wrote:
> > How does one type cast in PyQt4? For example, a
> QObject to a QAction?
> Why would you ever need it? PyQt will return a QAction if
> the C++ instance
> is a QAction.
> Phil

--- On Tue, 3/31/09, Christian <chrisde88 at yahoo.de> wrote:

> From: Christian <chrisde88 at yahoo.de>
> Subject: Re: [PyQt] Type casting
> To: pyqt at riverbankcomputing.com
> Date: Tuesday, March 31, 2009, 11:06 AM
> Hi Rendezvous,
> that's not necessary and therefore not possible in python
> due to the concept of duck typing. That means not the
> variable itself determines the type, but the content.
> Or do you mean something different?
> Christian


More information about the PyQt mailing list