Unsolved QMenu addSection Not Showing
-
Is there any reason why the
addSection
function of aQMenu
would have no effect?For example, the following code:
QMenu menu; menu.addSection("Connected"); menu.addAction("None"); menu.addSeparator(); menu.addSection("Available"); menu.addAction("None"); menu.addSeparator(); menu.addAction("Quit");
Results in a menu with just the actions and separators visible.
-
Hi,
From the documentation from addSection:
The rendering of the hint is style and platform dependent. Widget styles can use the text information in the rendering for sections, or can choose to ignore it and render sections like simple separators.
-
@SGaist thanks for the clarification - so I can presume then, that Windows does not render these sections. Thanks again.
-
I've experienced this very same problem and although I'm very late to the discussion I have to say that it's possible to render separators and separator labels in Windows. The trick is to use a widget style that supports these features.
One such widget theme is the "fusion" style shown in Qt's wiget gallery. For a quick test, just run the Qt application with the fusion style by passing the "-style fusion" command line argument.
-
under macos, there is also no text.
I would have expected this method to create a disabled entry in the menu, it would be more helpful and consistent across the different styles. -
@3nids By default Qt OS specific styles follow their respective OS guidelines. These OSs have all their specific guidelines which may or may not have things in common with the others.