[PyQt] New Feature - Keyword Arguments for Properties and Signals

Phil Thompson phil at riverbankcomputing.com
Thu Sep 10 07:42:06 BST 2009


On Thu, 10 Sep 2009 01:25:12 +0300, "Ville M. Vainio" <vivainio at gmail.com>
wrote:
> Accidentally omitted list in CC, resending...
> 
> 
> On Mon, Sep 7, 2009 at 10:57 AM, Phil Thompson
> <phil at riverbankcomputing.com> wrote:
> 
>> For example, the following calls...
>>
>>    act = QAction("Save", parent)
>>    act.setShortcut(QKeySequence.Save)
>>    act.setStatusTip("Save the document")
>>    act.triggered.connect(self.save)
>>
>> ...can be replaced by...
>>
>>    act = QAction("Save", parent, shortcut=QKeySequence.Save,
>>            statusTip="Save the document", triggered=self.save)
> 
> Very cool stuff!
> 
> Now, can we have something that does the same thing outside constructor?
> E.g.
> 
> act = menu.addAction('blah')
> act.configure(triggered=self.save, statusTip="Save the document")

Possibly, but it will need a prefix to avoid potential name clashes.

> Also, is this a "safe" way to connect signals so that we get an
> exception on bad signal name (as in the new style signal api, and as
> opposed to the old c++ style signal binding)?

That's not possible because the following needs to work...

class ExtendedQAction(QAction, MyMixin):
    def __init__(text, parent, **kwargs):
        QAction.__init__(self, text, parent, **kwargs)
        MyMixin.__init__(self, **kwargs)

Phil


More information about the PyQt mailing list