PyQt6 / Confusion over enum and flags
John F Sturtz
john at sturtz.org
Wed Dec 18 16:35:54 GMT 2024
Argh! Thank you. I had a hunch this was going to turn out to be a dumb
question when I posted it, and sure enough ... I guess it was late and I
was bleary-eyed when I was messing around with it.
I assumed the problem was with the first argument, because that was
(partly) what the error message said:
Traceback (most recent call last):
File "<pyshell#4>", line 1, in <module>
QKeyCombination(Qt.KeyboardModifier.ControlModifier, key=65)
TypeError: arguments did not match any overloaded call:
QKeyCombination(key: Qt.Key = Qt.Key_unknown): argument 1 has
unexpected type 'KeyboardModifier'
QKeyCombination(modifiers: Qt.Modifier, key: Qt.Key = Qt.Key_unknown):
argument 1 has unexpected type 'KeyboardModifier'
QKeyCombination(modifiers: Qt.KeyboardModifier, key: Qt.Key =
Qt.Key_unknown): argument 'key' has unexpected type 'int'
QKeyCombination(a0: QKeyCombination): argument 1 has unexpected type
'KeyboardModifier'
I see now that that part of the error message refers to the prototype
with only one argument, which isn't the one I was trying to use. The
message I should have been looking at was the third one down, and then I
would have seen the mistake you pointed out to me. 😖
Thanks again. (Now slinking off with my tail between my legs ...)
/John
------ Original Message ------
>From "Charles" <peacech at gmail.com>
To "John F Sturtz" <john at sturtz.org>
Cc pyqt at riverbankcomputing.com
Date 12/17/2024 11:57:53 PM
Subject Re: PyQt6 / Confusion over enum and flags
> > 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.KeyboardModifierenum 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/591ac918/attachment.htm>
More information about the PyQt
mailing list