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

Menus misplaced if items added after aboutToShow() using RTL mode

    XMLWordPrintable

Details

    • Bug
    • Resolution: Done
    • P2: Important
    • 4.6.0
    • 4.4.1
    • Widgets: Main Window
    • None
    • 68ab3b34571cfdde4002de9982388f9eec4d9939, Follow-up fix in Qt 5: bf178c77dda1db56ae698c1d31a6e3f685f4830f

    Description

      If running an application in RTL mode and dynamicly adding QActions to a QMenu when aboutToShow() is emitted. The menu will be shown incorrectly shifted to the right.

      Example code:

      #include <QtGui>

      class BorkedMenu: public QMenu
      {
      Q_OBJECT
      public:
      BorkedMenu( QWidget *parent): QMenu(parent)

      { connect(this, SIGNAL(aboutToShow()), this, SLOT(aboutToShow())); }

      public slots:
      void aboutToShow()

      { if (!actions().isEmpty()) return; addAction( new QAction("Today", parent() ) ); addAction( new QAction("Yesterday", parent() ) ); addAction( new QAction("A week ago", parent() ) ); }

      };

      #include "main.moc"

      int main( int arc, char *argv[] )
      {
      QApplication app(arc, argv);
      app.setLayoutDirection(Qt::RightToLeft);
      QMainWindow *window = new QMainWindow;
      QMenu *menu;

      menu = window->menuBar()>addMenu( window>tr("&File") );
      menu->addAction( new QAction("New", window) );
      menu->addAction( new QAction("Open", window) );
      menu->addAction( new QAction("Quit", window) );
      menu = window->menuBar()>addMenu( window>tr("&Edit") );
      menu->addAction( new QAction("Copy", window) );
      menu->addAction( new QAction("Cut", window) );
      menu->addAction( new QAction("Paste", window) );

      // this menu will be borked
      menu = new BorkedMenu( window );
      menu->setTitle("&History");
      window->menuBar()->addMenu(menu);

      menu = window->menuBar()>addMenu( window>tr("&Help") );
      menu->addAction( new QAction("About", window) );
      QTextEdit *e = new QTextEdit( window );
      e->setHtml(
      "<p dir='ltr'>"
      "To reproduce this bug, open the History menu. The first time you open the bookmark menu, it will "
      "be shifted to the right. This is because the calculation of the position of the "
      "menu is done before the <b>aboutToShow()</b> signal is emmited, but many applications "
      "(KDE for example) will add QActions to the QMenu on a callback method connected to this "
      "signal, which means a new location need to be computed.<br><br>"
      "</p>"
      );
      window->setCentralWidget( e );
      window->showMaximized();
      window->show();

      return app.exec();
      }

      Attachments

        Issue Links

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

          Activity

            People

              Unassigned Unassigned
              xcm Martin Petersson (Inactive)
              Votes:
              0 Vote for this issue
              Watchers:
              1 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved:

                Gerrit Reviews

                  There are no open Gerrit changes