Uploaded image for project: 'Qt'
  1. Qt
  2. QTBUG-47406

Do not close QMenu if click inside QWidgetAction triggered

    XMLWordPrintable

Details

    • Bug
    • Resolution: Unresolved
    • P4: Low
    • None
    • 5.5.0
    • None
    • Win8.1

    Description

      If you have a QWidgetAction with e.g. a label and a SpinBox and the user is clicking on the label, the menu will be closed. As user I find this behavior strange, because I expect that the menu will be closed, in case it is losing its context or an action is triggered.

      My current solution is to catch mousePressEvent and mouseReleaseEvent in default widget of QWidgetAction and accept all events, to prevent this behavior. But this is not really a nice solution because widget inside of QWidgetAction don't should know that it is inside of a QMenu/QWidgetAction and has to catch this events. Alternate would be to overwrite event filter of QWidgetAction (not tested) as far as I can see.

      Because all my tested (and popular tools, e.g. options in Office, menu in Firefox, ...) behave differently, it is for me as user an bug - and should be fixed. Compare attached screencasts of qt with Firefox, Opera und PowerPoint. You always see menu will not be closed until I click on something that causes an action, except at where the menu will be always closed.

      Source of Qt example:

      #include <QApplication>
      #include <QHBoxLayout>
      #include <QLabel>
      #include <QMenu>
      #include <QMenuBar>
      #include <QMainWindow>
      #include <QSpinBox>
      #include <QWidgetAction>
      
      int main(int argc, char * argv[])
      {
          QApplication qapp(argc,argv);
      	QMainWindow mainWindow;
      
      	auto menuBar = mainWindow.menuBar();
      	auto menu = menuBar->addMenu("Menu");
      
      	auto layout = new QHBoxLayout();
      	layout->addWidget(new QLabel("Test"));
      	layout->addWidget(new QSpinBox());
      
      	auto widget = new QWidget();
      	widget->setLayout(layout);
      
      	auto action = new QWidgetAction(menu);
      	action->setDefaultWidget(widget);
      	menu->addAction("Item Before");
      	menu->addAction(action);
      	menu->addAction("Item After");
      
      	mainWindow.show();
          
      	qapp.exec();
      }
      

      Attachments

        1. ff.gif
          ff.gif
          94 kB
        2. opera.gif
          opera.gif
          106 kB
        3. powerpoint.gif
          powerpoint.gif
          132 kB
        4. qt.gif
          qt.gif
          94 kB
        No reviews matched the request. Check your Options in the drop-down menu of this sections header.

        Activity

          People

            qt.team.quick.subscriptions Qt Quick and Widgets Team
            EliteScience Heiko Thiel
            Votes:
            2 Vote for this issue
            Watchers:
            6 Start watching this issue

            Dates

              Created:
              Updated:

              Gerrit Reviews

                There are no open Gerrit changes