[PyKDE] QAccel automatically sends signal

David Boddie david at boddie.org.uk
Fri Apr 15 02:02:48 BST 2005


On Thu, 14 Apr 2005 16:05:07, Alfred Young wrote:

> self.shortcutKey = QAccel(self)
> id = self.shortcutKey.insertItem(Qt.Key_Enter)
> self.shortcutKey.connectItem(id, self.defaultButton,
> SLOT(self.defaultButton.clicked()))
>
> However as soon as I invoke connectItem() it appears that the
> defaultButton's slot is activated.  I've tried a number of ways to get
> around this but no luck.

When you write self.defaultButton.clicked() you are actually calling
that function there and then.

> Does anyone know what I may be doing wrong?  Maybe I'm not understanding
> QAccel's abilities?

You need to pass the slot's name as a string:

  self.shortcutKey.connectItem(id, self.defaultButton, SLOT("clicked()"))

Alternatively, since this is Python, you can also write

  self.shortcutKey.connectItem(id, self.defaultButton.clicked)

which is much nicer to read. :-)

David




More information about the PyQt mailing list