[prev in list] [next in list] [prev in thread] [next in thread] 

List:       pykde
Subject:    Re: Pre-select QMenu item
From:       Luc-Henri Jolly Scienomics <luc-henri.jolly () scienomics ! com>
Date:       2024-03-03 9:24:57
Message-ID: B272FF5A-0A76-4B37-8B09-81FC07B09003 () scienomics ! com
[Download RAW message or body]

Hi John,

I'm nit a specialist (far from that). But what I understand from the doc is that

setActiveAction

sets the action to the ***currently*** highlighted item. It is not tell that it's \
made to highlight the item. 

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. 

In your big app, this is not the same situation. Did you try to select by default the \
second or third item? 

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.

Hope that helps! 

Le 3 mars 2024 01:21:51 GMT+01:00, John F Sturtz <john@sturtz.org> a écrit  :
> Hello good folks.
> 
> 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. 
> I am creating a QMenu object on the fly and then using .exec() 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. 
> I'd have thought this would be simple enough to accomplish, using \
> .setActiveAction().   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: 
> menu = QtWidgets.QMenu()
> for s in ('Foo', 'Bar', 'Baz'):
> menu.addAction(QtGui.QIcon('account.png'), s)
> menu.setActiveAction(menu.actions()[0])
> menu.exec(self.mapToGlobal(QtCore.QPoint(20, 20)))
> 
> In my smaller test program, this does just what I expect:   When the menu pops up, \
> the first item is selected. 
> Here's the rub:   When I put essentially the exact same code into my larger app, it \
> behaves oddly.   The first 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 \
> next time I display the popup, it does work.   And every time thereafter, until the \
> app shuts down. 
> I realize this is a bit of a slippery question, because I can't post the code that \
> doesn't 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. 
> Thanks!
> 
> /John

-- 
Luc-Henri Jolly
System manager Scienomics in Paris


[Attachment #3 (text/html)]

<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 &lt;john@sturtz.org&gt; 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.&nbsp; But the issue is
 complicated by the fact that what I am trying to do works perfectly 
well (seemingly) in my small test program.&nbsp; 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.&nbsp; 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>.&nbsp; And 
indeed, in the small test program I wrote 
(which is in the zip file attached), it does seem to work as I expect.&nbsp; 
The pertinent code is:<br>
<br>
<span style="font-family: \
monospace;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; menu = \
 QtWidgets.QMenu()</span><span style="font-family: monospace;"><br>
</span><span style="font-family: \
monospace;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; for s \
in  ('Foo', 'Bar', 'Baz'):</span><span style="font-family: monospace;"><br>
</span><span style="font-family: \
monospace;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; \
 menu.addAction(QtGui.QIcon('account.png'), s)</span><span style="font-family: \
monospace;"><br> </span><span style="font-family: \
monospace;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;  \
menu.setActiveAction(menu.actions()[0])</span><span style="font-family:  \
monospace;"><br> </span><span style="font-family: \
monospace;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;  \
menu.exec(self.mapToGlobal(QtCore.QPoint(20, 20)))</span><br> <br>
In my smaller test program, this does just what I expect:&nbsp; When the menu
 pops up, the first item is selected.<br>
<br>
Here's the rub:&nbsp; When I put essentially the exact same code into my 
larger app, it behaves oddly.&nbsp; The <span style="font-style: \
italic;">first</span>  time I display the popup menu, it doesn't work.&nbsp; The \
popup menu  displays, but it does not select the first item as I would expect.&nbsp; \
The <span style="font-style: italic;">next</span> time I display the popup, it  does \
work.&nbsp; 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.&nbsp; Apparently, something that is going on with the 
larger app is messing with this.&nbsp; 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>



[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic