I have a derived MyQMenu from QMenu and want to enable scrolling in case the menu expands too much.
This menu contains a lot of check boxes.
class MyQMenu : public QMenu{
...
void customizeStyle(){
QString menuStyle(
"QMenu{"
"menu-scrollable: 1;"
"}"
);
this->setStyleSheet(menuStyle);
}
...
};
It does enable scrolling, but now, the menu height takes the entire screen height.
After some searching, I have tried:
Reimplement
sizeHint(), and give a fixed height (e.g. 600). The menu height is fixed, but the scroll bar disappeared, so I cannot scroll the menu.Customize
MyMenuStylefromQProxyStyleto disableQStyle::SH_Menu_FillScreenWithScroll, but it does not work.Customize
MyMenuStylefromQProxyStyleto disableQStyle::SH_Menu_FillScreenWithScroll, and setQStyle::PM_MenuDesktopFrameWidthto100, it works, but has a new problem: scroll bar disappeared when I clicked on one checkbox.
Is it possible to make QMenu scrollable, and with a fixed or proper height, instead of taking the entire screen height?