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

Setting WA_TranslucentBackground in the event loop of a menu change the behavior of the menu

    XMLWordPrintable

Details

    Description

      On Linux, if the attribute WA_TranslucentBackground is set in the event loop of a QMenu (menu.exec()), the menu do not close itself when it loose the focus.

      Here is a code to reproduce the problem (right click in the main window, then click elsewhere in the window):

      #include <QApplication>
      #include <QContextMenuEvent>
      #include <QMenu>
      #include <QPlastiqueStyle>
      #include <QWidget>

      class Style : public QPlastiqueStyle
      {
      public:
      Style() : QPlastiqueStyle()
      {
      }

      void polish(QWidget *widget)

      { if (qobject_cast<QMenu*>(widget)) widget->setAttribute(Qt::WA_TranslucentBackground); }

      };

      class MainWindow : public QWidget
      {
      public:
      MainWindow() : QWidget(), style(new Style)
      {
      }

      ~MainWindow()

      { delete style; }

      void contextMenuEvent(QContextMenuEvent *event)

      { QMenu menu; for (int i = 0; i < 10; i++) menu.addAction(QString("Action ") + QString::number(i + 1)); menu.setStyle(style); menu.exec(event->globalPos()); }

      private:
      Style *style;
      };

      int main(int argc, char **argv)
      {
      QApplication app(argc, argv);
      MainWindow w;
      w.show();
      return app.exec();
      }

      Attachments

        No reviews matched the request. Check your Options in the drop-down menu of this sections header.

        Activity

          People

            goffart Olivier Goffart (closed Nokia identity) (Inactive)
            poulain Benjamin Poulain (closed Nokia identity) (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Gerrit Reviews

                There are no open Gerrit changes