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

setCursor does not work in QGraphicsView if set on a QGraphicsItem in the view.

    XMLWordPrintable

Details

    Description

      If you have set the cursor for some QGraphicsItems you can no longer change the cursor for the view in for example a mouseReleaseEvent.

      In the example code belove the cursor for the view is originaly set to the PointingHandCursor but it does not change on the mouseReleaseEvent. If you remove the cursor setting for the items it will change on every mouseReleaseEvent.

      Example Code:
      
      #include <QtGui>
      
      class QTCursorTest : public QGraphicsView
      {
      
      public:
          QTCursorTest::QTCursorTest(QWidget *parent = 0) : QGraphicsView(parent)
          {
               setScene(new QGraphicsScene);
               scene()->addRect(0, 0, 100, 100)->setCursor(Qt::CrossCursor); // remove these calls to setCursor
               scene()->addRect(120, 120, 50, 50)->setCursor(Qt::WaitCursor); // and setCursor for the view works again.
               setCursor(Qt::PointingHandCursor);
               
          }
      
          void QTCursorTest::mouseReleaseEvent(QMouseEvent *event)
          {
              setCursor(Qt::CursorShape(rand() % 18));
              qDebug() << "Now I should change the cursor";
              QGraphicsView::mouseReleaseEvent(event);
          }
      
      };
      
      
      int main(int argc, char *argv[])
      {
          QApplication app(argc, argv);
      
          QTCursorTest widget;
          widget.show();
          
          return app.exec();
      }
      
      

      Attachments

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

        Activity

          People

            bjnilsen Bjørn Erik Nilsen
            xcm Martin Petersson (Inactive)
            Votes:
            3 Vote for this issue
            Watchers:
            4 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Gerrit Reviews

                There are no open Gerrit changes