Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. QML and Qt Quick
  4. How to change the cursor shape

How to change the cursor shape

Scheduled Pinned Locked Moved Solved QML and Qt Quick
3 Posts 2 Posters 8.7k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • W Offline
    W Offline
    webberg
    wrote on 8 Sept 2016, 02:16 last edited by
    #1

    Hello,
    I extend a class from QQuickPaintedItem and implement virtual function paint. Then I want to change mouse cursor to Qt::IBeamCursor when mouse move into text area where I draw. I wrote the following function to reply mouse move event:

    Q_INVOKABLE void MyView::mouseMove(int x, int y)
    {
        if(IsInTextArea() && cursor().shape()!=Qt::IBeamCursor){
            cursor().setShape(Qt::IBeamCursor);
            return;
        }
        if(!IsInTextArea() && cursor().shape()!= Qt::ArrowCursor){
            cursor().setShape(Qt::ArrowCursor);
            return;
        }
    }
    

    I detect it has called cursor().setShape(Qt::IBeamCursor); but nothing changed. So what's wrong with my code? thank you.

    R 1 Reply Last reply 8 Sept 2016, 06:47
    0
    • W webberg
      8 Sept 2016, 02:16

      Hello,
      I extend a class from QQuickPaintedItem and implement virtual function paint. Then I want to change mouse cursor to Qt::IBeamCursor when mouse move into text area where I draw. I wrote the following function to reply mouse move event:

      Q_INVOKABLE void MyView::mouseMove(int x, int y)
      {
          if(IsInTextArea() && cursor().shape()!=Qt::IBeamCursor){
              cursor().setShape(Qt::IBeamCursor);
              return;
          }
          if(!IsInTextArea() && cursor().shape()!= Qt::ArrowCursor){
              cursor().setShape(Qt::ArrowCursor);
              return;
          }
      }
      

      I detect it has called cursor().setShape(Qt::IBeamCursor); but nothing changed. So what's wrong with my code? thank you.

      R Offline
      R Offline
      raven-worx
      Moderators
      wrote on 8 Sept 2016, 06:47 last edited by
      #2

      @webberg
      You should rather use QWidget::setCursor() than cursor().setShape():

      Q_INVOKABLE void MyView::mouseMove(int x, int y)
      {
          if(IsInTextArea() && cursor().shape()!=Qt::IBeamCursor){
              this->setCursor(Qt::IBeamCursor);
              return;
          }
          if(!IsInTextArea() && cursor().shape()!= Qt::ArrowCursor){
              this->setCursor(Qt::ArrowCursor);
              return;
          }
      }
      

      --- SUPPORT REQUESTS VIA CHAT WILL BE IGNORED ---
      If you have a question please use the forum so others can benefit from the solution in the future

      W 1 Reply Last reply 8 Sept 2016, 07:06
      1
      • R raven-worx
        8 Sept 2016, 06:47

        @webberg
        You should rather use QWidget::setCursor() than cursor().setShape():

        Q_INVOKABLE void MyView::mouseMove(int x, int y)
        {
            if(IsInTextArea() && cursor().shape()!=Qt::IBeamCursor){
                this->setCursor(Qt::IBeamCursor);
                return;
            }
            if(!IsInTextArea() && cursor().shape()!= Qt::ArrowCursor){
                this->setCursor(Qt::ArrowCursor);
                return;
            }
        }
        
        W Offline
        W Offline
        webberg
        wrote on 8 Sept 2016, 07:06 last edited by
        #3

        @raven-worx Thanks! I found I use MouseArea in my view. I changed the cursor of my view. But in fact, I should change the cursor shape of MouseArea in QML.

        1 Reply Last reply
        0

        3/3

        8 Sept 2016, 07:06

        • Login

        • Login or register to search.
        3 out of 3
        • First post
          3/3
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • Users
        • Groups
        • Search
        • Get Qt Extensions
        • Unsolved