1

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 MyMenuStyle from QProxyStyle to disable QStyle::SH_Menu_FillScreenWithScroll, but it does not work.

  • Customize MyMenuStyle from QProxyStyle to disable QStyle::SH_Menu_FillScreenWithScroll, and set QStyle::PM_MenuDesktopFrameWidth to 100, 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?

woody
  • 11
  • 1

0 Answers0