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

Menu pop-up of a QToolButton embedded into a QGraphicsScene is shown in the wrong location.

    XMLWordPrintable

Details

    • 56d091a4ea0276a4af732bfc8c701f392e57b9a1 (qtbase/5.5, 10.4.2015, 5.5)

    Description

      I've embedded a QToolButton into a QGraphicsScene and added a menu to it via QToolButton::setMenu. Pressing the QToolButton the menu shall then appear:

      #include <QApplication>
      #include <QtWidgets>
      
      int main(int argc, char *argv[])
      {
          QApplication a(argc, argv);
      
          QGraphicsView view;
          QGraphicsScene *scene = new QGraphicsScene(&view);
          view.setScene(scene);
      
          QToolButton *toolButton = new QToolButton;
          toolButton->resize(100, 30);
          QMenu *menu = new QMenu("Options");
          menu->addAction("A");
          menu->addAction("B");
          menu->addAction("C");
          toolButton->setMenu(menu);
          scene->addWidget(toolButton);
      
          view.resize(300, 300);
          view.show();
      
          return a.exec();
      }
      

      There is a situation now where the popup appears at the wrong position.

      The situation is the following:
      1) There is only one view.
      2) The view's viewport rect does not match the scene rect (the view only shows part of the scene).

      Having two or more views or showing the full scene with the one view results in the position to be correct.

      What I found out:
      I tracked it down to QWidgetPrivate::screenGeometry(const QWidget *widget). If the widget is embedded into a QGraphicsScene via a proxy and if there is just one view then the view's viewport rect is returned as screenGeometry, otherwise the scene rect is returned.

      So in my situation the QToolButton gets a 'wrong' rect to calculate the popup position.

      I would have expected screenGeometry to always return the scene rect when the widget is embedded into a QGraphicsScene. It is irritating that the behaviour depends on the number of used views. What is the rational behind this decision?

      Attachments

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

        Activity

          People

            kleint Friedemann Kleint
            peersch Peer Schneider
            Votes:
            2 Vote for this issue
            Watchers:
            6 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Gerrit Reviews

                There are no open Gerrit changes