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.
-
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.
-
Here is a workaround if you only have your first section that is not showing :
Add aQWidgetAction
before your firstaddSection
Add an emptyQWidget
as default widget of theQWidgetAction
And voilĂ , your first section is now displayed with nothing visible above it.