<html><head><style id="css_styles" type="text/css"><!--blockquote.cite { margin-left: 5px; margin-right: 0px; padding-left: 10px; padding-right:0px; border-left: 1px solid #cccccc }
blockquote.cite2 {margin-left: 5px; margin-right: 0px; padding-left: 10px; padding-right:0px; border-left: 1px solid #cccccc; margin-top: 3px; padding-top: 0px; }
a img { border: 0px; }
table { border-collapse: collapse; }
li[style='text-align: center;'], li[style='text-align: center; '], li[style='text-align: right;'], li[style='text-align: right; '] { list-style-position: inside;}
body { font-family: Calibri; font-size: 12pt; }
.quote { margin-left: 1em; margin-right: 1em; border-left: 5px #ebebeb solid; padding-left: 0.3em; }
a.em-mention[href] { text-decoration: none; color: inherit; border-radius: 3px; padding-left: 2px; padding-right: 2px; background-color: #e2e2e2; }
--></style></head><body><div>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.</div><div><br /></div><div>I assumed the problem was with the first argument, because that was (partly) what the error message said:</div><div><br /></div><div><font face="Cascadia Mono" size="1" style="font-size: 13.3px;">Traceback (most recent call last):
</font></div><div><font face="Cascadia Mono" size="1" style="font-size: 13.3px;"> File "<pyshell#4>", line 1, in <module>
</font></div><div><font face="Cascadia Mono" size="1" style="font-size: 13.3px;"> QKeyCombination(Qt.KeyboardModifier.ControlModifier, key=65)
</font></div><div><font face="Cascadia Mono" size="1" style="font-size: 13.3px;">TypeError: arguments did not match any overloaded call:
</font></div><div><font face="Cascadia Mono" size="1" style="font-size: 13.3px;" color="#a64d79"> QKeyCombination(key: Qt.Key = Qt.Key_unknown): argument 1 has unexpected type 'KeyboardModifier'
</font></div><div><font face="Cascadia Mono" size="1" style="font-size: 13.3px;"> QKeyCombination(modifiers: Qt.Modifier, key: Qt.Key = Qt.Key_unknown): argument 1 has unexpected type 'KeyboardModifier'
</font></div><div><font face="Cascadia Mono" size="1" style="font-size: 13.3px;" color="#3d85c6"> QKeyCombination(modifiers: Qt.KeyboardModifier, key: Qt.Key = Qt.Key_unknown): argument 'key' has unexpected type 'int'
</font></div><div><font face="Cascadia Mono" size="1" style="font-size: 13.3px;"> QKeyCombination(a0: QKeyCombination): argument 1 has unexpected type 'KeyboardModifier'
</font></div><div><br /></div><div>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. 😖</div><div><br /></div><div>Thanks again. (Now slinking off with my tail between my legs ...)</div><div><br /></div><div>/John</div>
<div><br /></div>
<div x-em-replyforwardheader=""><br /></div>
<div>
<div>------ Original Message ------</div>
<div>From "Charles" <<a href="mailto:peacech@gmail.com">peacech@gmail.com</a>></div>
<div>To "John F Sturtz" <<a href="mailto:john@sturtz.org">john@sturtz.org</a>></div>
<div>Cc <a href="mailto:pyqt@riverbankcomputing.com">pyqt@riverbankcomputing.com</a></div>
<div>Date 12/17/2024 11:57:53 PM</div>
<div>Subject Re: PyQt6 / Confusion over enum and flags</div></div><div x-em-quote=""><br /></div>
<div id="xadea61aa8c26497"><blockquote cite="CABthHP_5yj39doE=PwVMewpOYxR3HmXGv+LsZnCx4AD67Vz26w@mail.gmail.com" type="cite" class="cite2">
<div dir="ltr"><div class="gmail_default" style="font-family:arial,helvetica,sans-serif;font-size:small">>
<font face="Cascadia Mono" size="1" style="font-size:13.3px" class="gmail-">QKeyCombination(Qt.KeyboardModifier.ControlModifier, key=65)</font> <br /></div><div class="gmail_default" style="font-family:arial,helvetica,sans-serif;font-size:small"><br /></div><div class="gmail_default" style="font-family:arial,helvetica,sans-serif;font-size:small">You can't pass integer for enum, either use</div><div class="gmail_default" style="font-family:arial,helvetica,sans-serif;font-size:small"><br /></div><div class="gmail_default" style="font-family:arial,helvetica,sans-serif;font-size:small">
<font face="Cascadia Mono" size="1" style="font-size:13.3px" class="gmail-">QKeyCombination(Qt.KeyboardModifier.ControlModifier, key=Qt.Key.Key_A)</font></div><div class="gmail_default" style="font-family:arial,helvetica,sans-serif;font-size:small"><font face="Cascadia Mono" size="1" style="font-size:13.3px" class="gmail-"><br /></font></div><div class="gmail_default" style="font-family:arial,helvetica,sans-serif;font-size:small"><font face="Cascadia Mono" size="1" style="font-size:13.3px" class="gmail-">or</font></div><div class="gmail_default" style="font-family:arial,helvetica,sans-serif;font-size:small"><font face="Cascadia Mono" size="1" style="font-size:13.3px" class="gmail-"><br /></font></div><div class="gmail_default" style="font-family:arial,helvetica,sans-serif;font-size:small">
<font face="Cascadia Mono" size="1" style="font-size:13.3px" class="gmail-">QKeyCombination(Qt.KeyboardModifier.ControlModifier, key=Qt.Key(65))</font>
</div></div><br /><div class="gmail_quote gmail_quote_container"><div dir="ltr" class="gmail_attr">On Wed, Dec 18, 2024 at 12:38 PM John F Sturtz <<a href="mailto:john@sturtz.org">john@sturtz.org</a>> wrote:<br /></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div class="msg-8982048815171390447">
<div>Hi again.<div><br /></div><div>I am trying to port some <font face="Cascadia Mono" style="font-size:11pt" size="2">PyQt5</font> code to <font face="Cascadia Mono" style="font-size:13.3px" size="1">PyQt6</font>, and am running into confusion using the <font face="Cascadia Mono" style="font-size:14.7px" size="2">Qt.KeyboardModifier</font> <font face="Cascadia Mono" size="1" style="font-size:13.3px">enum</font> objects. I think (hope) the answer to this question would probably enlighten me more generally as to what I'm misunderstanding:</div><div><br /></div><div>Suppose I want to manually construct a <font face="Cascadia Mono" size="1" style="font-size:13.3px">QKeyCombination</font> object. This:</div><div><br /></div><div><font face="Cascadia Mono" size="1" style="font-size:13.3px"> QKeyCombination(Qt.KeyboardModifier.ControlModifier, key=65)</font></div><div><font face="Cascadia Mono" size="1" style="font-size:13.3px"><br /></font></div><div>fails, telling me that argument 1 has unexpected type 'KeyboardModifier'.</div><div><br /></div><div>Indeed the Qt documentation for <font face="Cascadia Mono" size="1" style="font-size:13.3px">QKeyCombination</font> says that argument 1 should be of type <font face="Cascadia Mono" size="1" style="font-size:13.3px">Qt::KeyboardModifiers</font> (plural). And that the type of <font face="Cascadia Mono" size="1" style="font-size:13.3px">Qt::KeyboardModifier</font> is <font face="Cascadia Mono" size="1" style="font-size:13.3px">enum</font>, and that of <font face="Cascadia Mono" size="1" style="font-size:13.3px">Qt::KeyboardModifiers</font> (plural) is <font face="Cascadia Mono" size="1" style="font-size:13.3px">flags</font>.</div><div><br /></div><div>It also says 'The <font face="Cascadia Mono" size="1" style="font-size:13.3px">KeyboardModifiers</font> type is a typedef for <font face="Cascadia Mono" size="1" style="font-size:13.3px">QFlags<KeyboardModifier></font>. It stores an OR combination of <font face="Cascadia Mono" size="1" style="font-size:13.3px">KeyboardModifier</font> values.'</div><div><br /></div><div>I think I understand (on some level) that the concept of <font face="Cascadia Mono" size="1" style="font-size:13.3px">QFlags</font> in Qt is not used in PyQt (anyway, I can't find anything called <font face="Cascadia Mono" size="1" style="font-size:13.3px">QFlags</font> in PyQt). But then I'm beating my head against the wall trying to figure out: What <i>does</i> the <font face="Cascadia Mono" size="1" style="font-size:13.3px">QKeyCombination</font> constructor want for its first argument?</div><div><br /></div><div>The PySide6 documentation for <font face="Cascadia Mono" size="1" style="font-size:13.3px">QKeyCombination</font> (unhelpfully) says:</div><div>
</div><blockquote style="margin:0px 0px 0px 40px;border:medium;padding:0px"><div><font face="Cascadia Mono" size="1" style="font-size:13.3px">__init__(modifiers[, key=Qt.Key_unknown])
</font></div><div><br /></div><div> Parameters:
</div><div> <font face="Cascadia Mono" size="1" style="font-size:13.3px">modifiers</font> – Combination of <font face="Cascadia Mono" size="1" style="font-size:13.3px">KeyboardModifier</font> </div><div> <font face="Cascadia Mono" size="1" style="font-size:13.3px">key</font> – Key </div></blockquote><div><br /></div><div>What sort of 'combination'? In what way do I combine <font face="Cascadia Mono" size="1" style="font-size:13.3px">KeyboardModifier</font> objects so as to satisfy <font face="Cascadia Mono" size="1" style="font-size:13.3px">QKeyCombination</font>'s demand for an object of type <font face="Cascadia Mono" size="1" style="font-size:13.3px">KeyboardModifiers</font> (plural) as the first argument?</div><div><br /></div><div>Thanks again!</div><div><br /></div><div>/John</div></div></div></blockquote></div>
</blockquote></div>
</body></html>