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

QWidget::setCursor() does not work on Mac

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Done
    • Icon: Not Evaluated Not Evaluated
    • None
    • 5.2.1
    • Widgets: Main Window
    • None
    • OSX 10.9.2
    • macOS

      QWidget::setCursor() has no effect on windows which are created beneath the mouse (ie. you need to move the cursor outside the window/widget and back in again before setCursor() starts to work correctly. This is most noticeable for windows which are created maximised. The following code shows the problem :

      setCursorTest.cpp
      #include <QtWidgets/QApplication>
      #include <QtWidgets/QWidget>
      
      class TestWindow : public QWidget
      {
         public :
         
            TestWindow()
            {
               setMouseTracking( true );
      	 setWindowState( windowState() | Qt::WindowMaximized );
            }
         
            virtual void mouseMoveEvent( QMouseEvent* event )
            {
               static uint8_t shape = Qt::ArrowCursor;
               
               setCursor( QCursor( ( Qt::CursorShape ) shape ) );
               
               shape = ++shape % Qt::LastCursor;
            }
      };
      
      int main( int argc, char** argv )
      {
         QApplication app( argc, argv );
      
         TestWindow window;
         window.setVisible( true );
         
         return app.exec();
      }
      

      The cursor should change every time the mouse moves, but does not (until the mouse leaves the window and re-enters).

      For what it's worth, the root of the problem appears to be in QCocoaWindow.mm where m_windowUnderMouse is initialised to false, regardless of the mouse position.

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

            Unassigned Unassigned
            greatwhite Rob Fearnside
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated:
              Resolved:

                There are no open Gerrit changes