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. QMl "line" can't track the correct mouse position in real time
Forum Updated to NodeBB v4.3 + New Features

QMl "line" can't track the correct mouse position in real time

Scheduled Pinned Locked Moved Unsolved QML and Qt Quick
8 Posts 4 Posters 1.2k Views 2 Watching
  • 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.
  • N Offline
    N Offline
    nature
    wrote on last edited by
    #1

    In the process of moving the mouse, I want the X attribute of "line" to change with MouseX at the same time , but when I move the mouse faster, "line" can't track the correct mouse position in real time(there is a interval between "line" and mouseX position) . What can I do to solve this problem (is it the refresh rate problem?)

    import QtQuick 2.14
    import QtQuick.Window 2.14
    
    Window {
        visible: true
        width: 640
        height: 480
        title: qsTr("Hello World")
    
        Rectangle{
            id:backgroup
            width: parent.width
            height: 100
            anchors.centerIn: parent
            color: "#131314"
    
            MouseArea {
                id:area
                anchors.fill: parent
                hoverEnabled: true
    
                onMouseXChanged: {
                   aaa.x = area.mouseX
                }
            }
    
            Rectangle {
                id: line
                width: 1
                height: 100
                x: 0
                anchors.verticalCenter: backgroup.verticalCenter
                color: "yellow"
            }
        }
    }
    
    KroMignonK J.HilkJ 2 Replies Last reply
    0
    • N nature

      In the process of moving the mouse, I want the X attribute of "line" to change with MouseX at the same time , but when I move the mouse faster, "line" can't track the correct mouse position in real time(there is a interval between "line" and mouseX position) . What can I do to solve this problem (is it the refresh rate problem?)

      import QtQuick 2.14
      import QtQuick.Window 2.14
      
      Window {
          visible: true
          width: 640
          height: 480
          title: qsTr("Hello World")
      
          Rectangle{
              id:backgroup
              width: parent.width
              height: 100
              anchors.centerIn: parent
              color: "#131314"
      
              MouseArea {
                  id:area
                  anchors.fill: parent
                  hoverEnabled: true
      
                  onMouseXChanged: {
                     aaa.x = area.mouseX
                  }
              }
      
              Rectangle {
                  id: line
                  width: 1
                  height: 100
                  x: 0
                  anchors.verticalCenter: backgroup.verticalCenter
                  color: "yellow"
              }
          }
      }
      
      KroMignonK Offline
      KroMignonK Offline
      KroMignon
      wrote on last edited by
      #2

      @nature said in QMl "line" can't track the correct mouse position in real time:

      onMouseXChanged: {
      aaa.x = area.mouseX
      }

      what is aaa ? I think this should be line

      It is an old maxim of mine that when you have excluded the impossible, whatever remains, however improbable, must be the truth. (Sherlock Holmes)

      N 1 Reply Last reply
      0
      • N nature

        In the process of moving the mouse, I want the X attribute of "line" to change with MouseX at the same time , but when I move the mouse faster, "line" can't track the correct mouse position in real time(there is a interval between "line" and mouseX position) . What can I do to solve this problem (is it the refresh rate problem?)

        import QtQuick 2.14
        import QtQuick.Window 2.14
        
        Window {
            visible: true
            width: 640
            height: 480
            title: qsTr("Hello World")
        
            Rectangle{
                id:backgroup
                width: parent.width
                height: 100
                anchors.centerIn: parent
                color: "#131314"
        
                MouseArea {
                    id:area
                    anchors.fill: parent
                    hoverEnabled: true
        
                    onMouseXChanged: {
                       aaa.x = area.mouseX
                    }
                }
        
                Rectangle {
                    id: line
                    width: 1
                    height: 100
                    x: 0
                    anchors.verticalCenter: backgroup.verticalCenter
                    color: "yellow"
                }
            }
        }
        
        J.HilkJ Offline
        J.HilkJ Offline
        J.Hilk
        Moderators
        wrote on last edited by
        #3

        @nature works fine for me, if I replace aaa with line like @KroMignon suggested.

        The only issue happens, when you jank the mouse outside of the window, then of course the line will remain where it is and not move to the border.

        Is that what you mean?


        Be aware of the Qt Code of Conduct, when posting : https://forum.qt.io/topic/113070/qt-code-of-conduct


        Q: What's that?
        A: It's blue light.
        Q: What does it do?
        A: It turns blue.

        N 2 Replies Last reply
        0
        • KroMignonK KroMignon

          @nature said in QMl "line" can't track the correct mouse position in real time:

          onMouseXChanged: {
          aaa.x = area.mouseX
          }

          what is aaa ? I think this should be line

          N Offline
          N Offline
          nature
          wrote on last edited by
          #4

          @KroMignon Yes I write wrong

          1 Reply Last reply
          0
          • J.HilkJ J.Hilk

            @nature works fine for me, if I replace aaa with line like @KroMignon suggested.

            The only issue happens, when you jank the mouse outside of the window, then of course the line will remain where it is and not move to the border.

            Is that what you mean?

            N Offline
            N Offline
            nature
            wrote on last edited by
            #5

            @J-Hilk you move stop , it works fine怂but when you move faster , the interval between line and mouse pointer is exist

            1 Reply Last reply
            0
            • J.HilkJ J.Hilk

              @nature works fine for me, if I replace aaa with line like @KroMignon suggested.

              The only issue happens, when you jank the mouse outside of the window, then of course the line will remain where it is and not move to the border.

              Is that what you mean?

              N Offline
              N Offline
              nature
              wrote on last edited by
              #6

              @J-Hilk E7D909A1-A582-41bb-9B78-0CF27D7CFB86.png
              you can see my screenshot when move faster,

              1 Reply Last reply
              0
              • KH-219DesignK Offline
                KH-219DesignK Offline
                KH-219Design
                wrote on last edited by
                #7

                The mouse cursor (in my understanding) is coupled to the Windows desktop and Windows display/windowing system in ways that other parts of your application are not.

                I can imagine that the Windows system process responsible for the whole display may be updating the actual cursor faster than the Qt GUI event loop receives (or handles) mouse movement events.

                (Note: this is just guesswork and "gut instinct" and a sprinkling of years-ago lived experience that I am speaking from. If anyone knows better, please correct me.)

                Depending on the ultimate goal of your application, if you have an absolute requirement that a line track EXACTLY to the mouse cursor at all times, then you might need to consider creating a custom cursor in the shape of a line, and telling the Windows system about your custom cursor.

                https://docs.microsoft.com/en-us/windows/win32/learnwin32/setting-the-cursor-image

                https://stackoverflow.com/questions/1536430/vc-win32-api-programming-how-to-change-mouse-cursor

                It might be possible to do this via Qt classes like QCursor: https://doc.qt.io/qt-5/qcursor.html

                Many years ago, I did something like what I just described in an application using eye-tracking. The eye-tracker acted as the mouse, and the only way to guarantee that the on-screen gaze marker was at all times in the same position as the mouse cursor was to make them one and the same: use a custom icon of the on-screen gaze marker to just replace the default arrow cursor system-wide (while the app was foregrounded). I was not using Qt at the time, so I cannot speak with any authority as to whether Qt would have helped me achieve a similar result.

                www.219design.com
                Software | Electrical | Mechanical | Product Design

                N 1 Reply Last reply
                2
                • KH-219DesignK KH-219Design

                  The mouse cursor (in my understanding) is coupled to the Windows desktop and Windows display/windowing system in ways that other parts of your application are not.

                  I can imagine that the Windows system process responsible for the whole display may be updating the actual cursor faster than the Qt GUI event loop receives (or handles) mouse movement events.

                  (Note: this is just guesswork and "gut instinct" and a sprinkling of years-ago lived experience that I am speaking from. If anyone knows better, please correct me.)

                  Depending on the ultimate goal of your application, if you have an absolute requirement that a line track EXACTLY to the mouse cursor at all times, then you might need to consider creating a custom cursor in the shape of a line, and telling the Windows system about your custom cursor.

                  https://docs.microsoft.com/en-us/windows/win32/learnwin32/setting-the-cursor-image

                  https://stackoverflow.com/questions/1536430/vc-win32-api-programming-how-to-change-mouse-cursor

                  It might be possible to do this via Qt classes like QCursor: https://doc.qt.io/qt-5/qcursor.html

                  Many years ago, I did something like what I just described in an application using eye-tracking. The eye-tracker acted as the mouse, and the only way to guarantee that the on-screen gaze marker was at all times in the same position as the mouse cursor was to make them one and the same: use a custom icon of the on-screen gaze marker to just replace the default arrow cursor system-wide (while the app was foregrounded). I was not using Qt at the time, so I cannot speak with any authority as to whether Qt would have helped me achieve a similar result.

                  N Offline
                  N Offline
                  nature
                  wrote on last edited by
                  #8

                  @KH-219Design Thank you for your reply. Our products are cross platform, including windows and Mac OS.

                  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