Re: [PySide] Custom QEvent subclassing

205 views
Skip to first unread message

Grant Limberg

unread,
Jan 27, 2011, 4:24:55 PM1/27/11
to pys...@lists.openbossa.org

On Jan 27, 2011, at 1:05 PM, Grant Limberg wrote:

> I'm beginning to look at PySide as a replacement for PyQt. The transition seems pretty straightforward so far, except for my QEvent subclasses. In PyQt, I defined new events like so:
>
> from PyQt4.QtCore import QEvent
>
> (EVENT_1,
> EVENT_2,
> EVENT_3) = range(QEvent.User, QEvent.User+3)
>
> With PySide however, this trhows an exception:
>
> TypeError: 'PySide.QtCore.QEvent' called with wrong argument types:
> PySide.QtCore.QEvent(int)
> Supported signatures:
> PySide.QtCore.QEvent(PySide.QtCore.QEvent.Type)
>
> What is the correct way of creating new QtCore.QEvent.Type s in PySide?
>
> Thanks,
>

I forgot to mention. System specs:

Python 2.7
Qt 4.7.1
PySide 1.0.0 beta 4

_______________________________________________
PySide mailing list
PyS...@lists.openbossa.org
http://lists.openbossa.org/listinfo/pyside

Hugo Parente Lima

unread,
Jan 27, 2011, 3:42:02 PM1/27/11
to pys...@lists.openbossa.org
On Thursday 27 January 2011 19:05:49 Grant Limberg wrote:
> I'm beginning to look at PySide as a replacement for PyQt. The transition
> seems pretty straightforward so far, except for my QEvent subclasses. In
> PyQt, I defined new events like so:
>
> from PyQt4.QtCore import QEvent
>
> (EVENT_1,
> EVENT_2,
> EVENT_3) = range(QEvent.User, QEvent.User+3)
>
> With PySide however, this trhows an exception:
>
> TypeError: 'PySide.QtCore.QEvent' called with wrong argument types:
> PySide.QtCore.QEvent(int)
> Supported signatures:
> PySide.QtCore.QEvent(PySide.QtCore.QEvent.Type)
>
> What is the correct way of creating new QtCore.QEvent.Type s in PySide?

If you sum a enum value plus a number the result will be a number.

Every enum is convertible to a number, but not all enums are convertible to
numbers because the enum values are a subset of all possible numbers.

About QEvent, this is a design flaw in Qt, in C++ the user must do a
static_cast from int to QEvent::Type to be able to create your own events, so
in Python you must do:

QEvent(QEvent.Type(someInt))
instead of
QEvent(someInt)

We don't do implicit casts from ints to enums as PyQt4 does because those
casts are completely unsafe and passing unsafe values to C++ could easily
result in nice segfaults :-).



> Thanks,
>
> Grant Limberg

--
Hugo Parente Lima
INdT - Instituto Nokia de Tecnologia

signature.asc

Grant Limberg

unread,
Jan 27, 2011, 5:07:43 PM1/27/11
to Hugo Parente Lima, pys...@lists.openbossa.org


Thanks for the info. Wrapping the value with QEvent.QType(int) works fine. I'm sure there are a few other places in my codebase that use ints in the place of Enums so I'll be on the lookout for this.

Grant Limberg

cedrus_masthead_logo.jpg

Grant Limberg

unread,
Jan 27, 2011, 4:05:49 PM1/27/11
to pys...@lists.openbossa.org
I'm beginning to look at PySide as a replacement for PyQt. The transition seems pretty straightforward so far, except for my QEvent subclasses. In PyQt, I defined new events like so:

from PyQt4.QtCore import QEvent

(EVENT_1,
EVENT_2,
EVENT_3) = range(QEvent.User, QEvent.User+3)

With PySide however, this trhows an exception:

TypeError: 'PySide.QtCore.QEvent' called with wrong argument types:
PySide.QtCore.QEvent(int)
Supported signatures:
PySide.QtCore.QEvent(PySide.QtCore.QEvent.Type)

What is the correct way of creating new QtCore.QEvent.Type s in PySide?

Thanks,

Grant Limberg

cedrus_masthead_logo.jpg
Reply all
Reply to author
Forward
0 new messages