<html theme="themeKey23rand818" iconset="color"><head>
<meta http-equiv="content-type" content="text/html; charset=utf-8">
</head><body style="color: rgb(25, 72, 105);" text="#194869"><div dir="auto">Hi John,<br><br>I'm nit a specialist (far from that). But what I understand from the doc is that<br><br>setActiveAction<br><br>sets the action to the ***currently*** highlighted item. It is not tell that it's made to highlight the item. <br><br>So, what I'm thinking is that it works in your little menu code, because it's the only one executed and it may be that showing the menu silently selects the first item, fue to another thing than the selectActiveAction. <br><br>In your big app, this is not the same situation. Did you try to select by default the second or third item? <br><br>When going from qt5 to Qt6, I've seen that using the activated signal in a comboBox does trigger the action in Qt5, but doesn't in Qt6.<br><br>Hope that helps! </div><br><br><div class="gmail_quote"><div dir="auto">Le 3 mars 2024 01:21:51 GMT+01:00, John F Sturtz <john@sturtz.org> a écrit :</div><blockquote class="gmail_quote" style="margin: 0pt 0pt 0pt 0.8ex; border-left: 1px solid rgb(204, 204, 204); padding-left: 1ex;">
Hello good folks.<br>
<br>
I think this is a relatively straightforward question. But the issue is
complicated by the fact that what I am trying to do works perfectly
well (seemingly) in my small test program. In my larger app, not so
much.<br>
<br>
I am creating a <span style="font-family: monospace;">QMenu</span>
object on the fly and then using <span style="font-family: monospace;">.exec()</span>
to
display it as a popup. What I would like to do is cause the first item
in the menu to be already selected when it pops up.<br>
<br>
I'd have thought this would be simple enough to accomplish, using
<span style="font-family: monospace;">.setActiveAction()</span>. And
indeed, in the small test program I wrote
(which is in the zip file attached), it does seem to work as I expect.
The pertinent code is:<br>
<br>
<span style="font-family: monospace;"> menu =
QtWidgets.QMenu()</span><span style="font-family: monospace;"><br>
</span><span style="font-family: monospace;"> for s in
('Foo', 'Bar', 'Baz'):</span><span style="font-family: monospace;"><br>
</span><span style="font-family: monospace;">
menu.addAction(QtGui.QIcon('account.png'), s)</span><span style="font-family: monospace;"><br>
</span><span style="font-family: monospace;">
menu.setActiveAction(menu.actions()[0])</span><span style="font-family:
monospace;"><br>
</span><span style="font-family: monospace;">
menu.exec(self.mapToGlobal(QtCore.QPoint(20, 20)))</span><br>
<br>
In my smaller test program, this does just what I expect: When the menu
pops up, the first item is selected.<br>
<br>
Here's the rub: When I put essentially the exact same code into my
larger app, it behaves oddly. The <span style="font-style: italic;">first</span>
time I display the popup menu, it doesn't work. The popup menu
displays, but it does not select the first item as I would expect. The <span style="font-style: italic;">next</span> time I display the popup, it
does work. And every time thereafter, until the app shuts down.<br>
<br>
I realize this is a bit of a slippery question, because I can't post the
code that <span style="font-style: italic;">doesn't</span> work -- only
the code that does. Apparently, something that is going on with the
larger app is messing with this. But I'm wondering if anyone has any
ideas as to why this might be the case, or what I might try to get
around it.<br>
<br>
Thanks!<br>
<br>
/John<span style="font-style: italic;"></span><span style="font-style:
italic;"></span><br>
</blockquote></div><div dir="auto"><div class='k9mail-signature'>-- <br>Luc-Henri Jolly<br>System manager Scienomics in Paris</div></div></body></html>