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 9.4k 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 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.

    raven-worxR 1 Reply Last reply
    0
    • W webberg

      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.

      raven-worxR Offline
      raven-worxR Offline
      raven-worx
      Moderators
      wrote on 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
      1
      • raven-worxR raven-worx

        @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 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

        • Login

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