<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">
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>
</body></html>