PyQt6 / Confusion over enum and flags
Charles
peacech at gmail.com
Wed Dec 18 05:57:53 GMT 2024
> QKeyCombination(Qt.KeyboardModifier.ControlModifier, key=65)
You can't pass integer for enum, either use
QKeyCombination(Qt.KeyboardModifier.ControlModifier, key=Qt.Key.Key_A)
or
QKeyCombination(Qt.KeyboardModifier.ControlModifier, key=Qt.Key(65))
On Wed, Dec 18, 2024 at 12:38 PM John F Sturtz <john at sturtz.org> wrote:
> Hi again.
>
> I am trying to port some PyQt5 code to PyQt6, and am running into
> confusion using the Qt.KeyboardModifier enum objects. I think (hope) the
> answer to this question would probably enlighten me more generally as to
> what I'm misunderstanding:
>
> Suppose I want to manually construct a QKeyCombination object. This:
>
> QKeyCombination(Qt.KeyboardModifier.ControlModifier, key=65)
>
> fails, telling me that argument 1 has unexpected type 'KeyboardModifier'.
>
> Indeed the Qt documentation for QKeyCombination says that argument 1
> should be of type Qt::KeyboardModifiers (plural). And that the type of
> Qt::KeyboardModifier is enum, and that of Qt::KeyboardModifiers (plural)
> is flags.
>
> It also says 'The KeyboardModifiers type is a typedef for
> QFlags<KeyboardModifier>. It stores an OR combination of KeyboardModifier
> values.'
>
> I think I understand (on some level) that the concept of QFlags in Qt is
> not used in PyQt (anyway, I can't find anything called QFlags in PyQt).
> But then I'm beating my head against the wall trying to figure out: What
> *does* the QKeyCombination constructor want for its first argument?
>
> The PySide6 documentation for QKeyCombination (unhelpfully) says:
>
> __init__(modifiers[, key=Qt.Key_unknown])
>
> Parameters:
> modifiers – Combination of KeyboardModifier
> key – Key
>
>
> What sort of 'combination'? In what way do I combine KeyboardModifier
> objects so as to satisfy QKeyCombination's demand for an object of type
> KeyboardModifiers (plural) as the first argument?
>
> Thanks again!
>
> /John
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://www.riverbankcomputing.com/pipermail/pyqt/attachments/20241218/be7001f4/attachment.htm>
More information about the PyQt
mailing list