<div dir="ltr"><div class="gmail_default" style="font-family:arial,helvetica,sans-serif;font-size:small">I tried it with the fusion style and it seems that there are some points where I was wrong:</div><div class="gmail_default" style="font-family:arial,helvetica,sans-serif;font-size:small">(1) the proxy style doesn't automatically use the application style, instead it uses the default style</div><div class="gmail_default" style="font-family:arial,helvetica,sans-serif;font-size:small">(2) the drawControl of fusion style doesn't use drawItemText for drawing the text</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">Anyway, here is what works for me (which works with the default or the fusion style)</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"><span style="font-family:monospace">from PyQt6.QtCore import Qt<br>from PyQt6.QtWidgets import QApplication, QMainWindow, QMenu, QProxyStyle, QStyle, QStyleOptionMenuItem<br><br><br>class ProxyStyle(QProxyStyle):<br> # uncomment this to use the fusion style<br> # def __init__(self):<br> # super().__init__('fusion')<br><br> def drawControl(self, element, option, painter, widget):<br> text = option.text<br> if element == QStyle.ControlElement.CE_MenuItem:<br> option.text = ''<br> super().drawControl(element, option, painter, widget)<br> if element == QStyle.ControlElement.CE_MenuItem:<br> painter.drawText(option.rect.adjusted(0, 0, -10, 0), Qt.AlignmentFlag.AlignVCenter | Qt.AlignmentFlag.AlignRight, text)<br><br><br>class MainWindow(QMainWindow):<br> def __init__(self):<br> super().__init__()<br><br> file_menu = QMenu('File', self)<br> file_menu.addAction('New')<br> file_menu.addAction('Open')<br> file_menu.addAction('Transform')<br><br> file_menu.setStyle(ProxyStyle())<br> self.menuBar().addMenu(file_menu)<br><br><br>if __name__ == '__main__':<br> app = QApplication([])<br> # app.setStyle('fusion') # uncomment this to use the fusion style<br> main_window = MainWindow()<br> main_window.show()<br> app.exec()</span><br><br></div></div><br><div class="gmail_quote gmail_quote_container"><div dir="ltr" class="gmail_attr">On Tue, Jun 10, 2025 at 3:36 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 class="msg7924640555019240856"><div><div><span>------ Original Message ------</span></div><div>
<div>From "Charles" <<a href="mailto:peacech@gmail.com" target="_blank">peacech@gmail.com</a>></div>
<div>To "John Sturtz" <<a href="mailto:john@sturtz.org" target="_blank">john@sturtz.org</a>></div>
<div>Cc <a href="mailto:pyqt@riverbankcomputing.com" target="_blank">pyqt@riverbankcomputing.com</a></div>
<div>Date 6/9/2025 12:20:29 PM</div>
<div>Subject Re: Re[2]: Customize QMenu display with QProxyStyle</div></div><div><br></div>
<div id="m_7924640555019240856xcb6327ed63f74e8"><blockquote cite="http://CABthHP8iiz_R0FC=Des8zYM=719Gqp6KiUwr5Qk1-HoZ54-9yw@mail.gmail.com" type="cite" class="m_7924640555019240856cite2">
<div dir="ltr"><div class="gmail_default" style="font-family:arial,helvetica,sans-serif;font-size:small">QProxyStyle automatically proxies to the used application style. </div></div></blockquote><font size="3" style="font-size:16px">I wondered if that mightn't be the case. That's fortunate.</font><br><br><blockquote cite="http://CABthHP8iiz_R0FC=Des8zYM=719Gqp6KiUwr5Qk1-HoZ54-9yw@mail.gmail.com" type="cite" class="m_7924640555019240856cite2"><div dir="ltr"><div class="gmail_default" style="font-family:arial,helvetica,sans-serif;font-size:small"><span style="font-family:"Segoe UI";font-size:12pt">I</span><span class="gmail_default">f you want rounded corners you need to port the whole C code in the</span></div><div><span class="gmail_default" style="font-family:arial,helvetica,sans-serif;font-size:small">OS style plugin that draws the menu item.</span></div><div><span class="gmail_default" style="font-family:arial,helvetica,sans-serif;font-size:small"><br></span></div><div><span class="gmail_default" style="font-family:arial,helvetica,sans-serif;font-size:small">Alternatively, use the fusion style which should be OS independent.</span></div><div><span class="gmail_default" style="font-family:arial,helvetica,sans-serif;font-size:small">With fusion style, overriding drawItemText should work.</span></div></div></blockquote>Actually, I didn't particularly want rounded corners, although I'm not sure I care that much.</div><div id="m_7924640555019240856xcb6327ed63f74e8"><br></div><div id="m_7924640555019240856xcb6327ed63f74e8">If I set fusion for the whole app [<font face="Cascadia Code">app.setStyle('Fusion')</font>], I don't get rounded corners by default. But if I apply the proxy style, then I do.</div><div id="m_7924640555019240856xcb6327ed63f74e8">If I don't set fusion for the whole app, I get rounded corners either way.</div><div id="m_7924640555019240856xcb6327ed63f74e8"><br></div><div id="m_7924640555019240856xcb6327ed63f74e8">And here's another interesting factoid: It seems that just the act of trying to create a proxy style based on the existing style causes a crash. This statement:</div><div id="m_7924640555019240856xcb6327ed63f74e8"><br></div><div id="m_7924640555019240856xcb6327ed63f74e8"> <font face="Cascadia Code" size="3" style="font-size:16px"> self.style = Style(file_menu.style())</font></div><div id="m_7924640555019240856xcb6327ed63f74e8"><br></div><div id="m_7924640555019240856xcb6327ed63f74e8">makes the app crash on exit, even if I never actually use the created proxy style.</div><div id="m_7924640555019240856xcb6327ed63f74e8"><br></div><div id="m_7924640555019240856xcb6327ed63f74e8">Anyway, thanks again for your help. All this gives me plenty to go forward with.</div><div id="m_7924640555019240856xcb6327ed63f74e8"><br></div><div id="m_7924640555019240856xcb6327ed63f74e8">/John</div><div id="m_7924640555019240856xcb6327ed63f74e8"><br></div>
</div></div></blockquote></div>