<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; }
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: 'Segoe UI'; 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; }
._em_placeholder {color: gray; border-bottom: 1px dotted lightblue;} ._em_placeholder:before{color:gray; content: '{{ ';} ._em_placeholder:after{color:gray; content: ' }}';}
--></style></head><body><div>Thanks again Charles.  In searching around, I found some examples that reimplemented <font face="Cascadia Code">drawItemText()</font> and some that reimplemented <font face="Cascadia Code" size="3" style="font-size: 16px;">drawControl()</font>.  The former seemed more intuitive to me (goes to show you what I know), so I went down the wrong rabbit hole.</div><div><br /></div><div>One more question if you will:  I've attached a newer version of my original sample, based on your suggestion.</div><div><br /></div><div>If I install the proxy style for the menu with:</div><div><br /></div><div><font face="Cascadia Code" size="3" style="font-size: 16px;">    file_menu.setStyle(Style())</font></div><div><br /></div><div>it works (items are right-justified).  But the menu has a slightly different appearance (on my system, rounded corners).  Not surprising, I suppose.  No arguments are passed to the <font face="Cascadia Code" size="3" style="font-size: 16px;">Style()</font> constructor, so it's creating one from scratch.</div><div><br /></div><div>I'd think the proper thing to do would be to derive the new style from the menu's previously-existing style:</div><div><br /></div><div><font face="Cascadia Code" size="3" style="font-size: 16px;">    file_menu.setStyle(Style(file_menu.style()))</font></div><div><br /></div><div>Wondering if this is a/the proper thing to do?  It seems to work, in that the menu then has the proper appearance (that is, one that is consistent with its appearance if I don't assign the proxy).</div><div><br /></div><div>But then when I exit the app, there's a long(ish -- about two seconds) delay.  If I run the app from a Command Prompt window, it's a couple seconds before the command prompt reappears -- I think the app is not merely exiting, but actually crashing.  Which makes me wonder if this is somehow not right?</div><div><br /></div><div>Thanks again!</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 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 6/9/2025 12:32:17 AM</div>
<div>Subject Re: Customize QMenu display with QProxyStyle</div></div><div x-em-quote=""><br /></div>
<div id="x5f41fe7e3253452"><blockquote cite="CABthHP8UgBjCnTaDHnLTYN6aPJSELOq-UwO_e42thA=tCS1Fkg@mail.gmail.com" type="cite" class="cite2">
<div dir="ltr"><div class="gmail_default" style="font-family:arial,helvetica,sans-serif;font-size:small">> 
Wrong QProxyStyle method. Tip: to know the right method, search for menuitem in 
<a href="https://codebrowser.dev/qt6/qtbase/src/widgets/styles/qcommonstyle.cpp.html">https://codebrowser.dev/qt6/qtbase/src/widgets/styles/qcommonstyle.cpp.html</a></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">Sorry, this is wrong. QMenu is drawn by the OS style plugin and does not call drawItemText. For example see: <a href="https://codebrowser.dev/qt6/qtbase/src/widgets/styles/qwindowsstyle.cpp.html#1012">https://codebrowser.dev/qt6/qtbase/src/widgets/styles/qwindowsstyle.cpp.html#1012</a></div></div><br /><div class="gmail_quote gmail_quote_container"><div dir="ltr" class="gmail_attr">On Mon, Jun 9, 2025 at 12:22 PM Charles <<a href="mailto:peacech@gmail.com">peacech@gmail.com</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 dir="ltr"><div class="gmail_default" style="font-family:arial,helvetica,sans-serif;font-size:small">Wrong QProxyStyle method. Tip: to know the right method, search for menuitem in <a href="https://codebrowser.dev/qt6/qtbase/src/widgets/styles/qcommonstyle.cpp.html">https://codebrowser.dev/qt6/qtbase/src/widgets/styles/qcommonstyle.cpp.html</a></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">class Style(QProxyStyle):<br />    def drawControl(self, element, option, painter, widget):<br />        if element == QStyle.ControlElement.CE_MenuItem:<br />            super().drawItemText(painter, option.rect, Qt.AlignmentFlag.AlignRight, option.palette, True, option.text, QPalette.ColorRole.ButtonText)<br />        else:<br />            return super().drawControl(element, option, painter, widget)</div></div><br /><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Mon, Jun 9, 2025 at 11:14 AM John 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>



<div>Hello again PyQt sages.  Hoping for some insight here -- despite a few hours' time fiddling with this, I don't seem to even be getting past square one.<div><br /></div><div>I'm trying to modify display of items in a <font face="Cascadia Code">QMenu</font> using <font face="Cascadia Code" size="3" style="font-size:16px">QProxyStyle</font>.  Basically, I've defined a class named <font face="Cascadia Code" size="3" style="font-size:16px">Style</font> that derives from <font face="Cascadia Code" size="3" style="font-size:16px">QProxyStyle</font>, and re-implements <font face="Cascadia Code" size="3" style="font-size:16px">drawItemText()</font> (which, just for starters, tries to right-justify the menu item text).</div><div><br /></div><div>I create a <font face="Cascadia Code" size="3" style="font-size:16px">QMenu</font> object, create an object of the <font face="Cascadia Code" size="3" style="font-size:16px">Style</font> class, and call <font face="Cascadia Code" size="3" style="font-size:16px">.setStyle()</font> to set it as the menu's style.</div><div><br /></div><div>It may or may not be the case that my <font face="Cascadia Code" size="3" style="font-size:16px">drawItemText()</font> implementation successfully right-justifies the text.  I'll never know, because it never gets called.  What (probably really basic thing) am I missing?</div><div><br /></div><div>Thanks!  [short sample code attached]</div><div><br /></div><div>/John</div></div></div></blockquote></div>
</blockquote></div>
</blockquote></div>
</body></html>