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. Help with crosshair
Forum Updated to NodeBB v4.3 + New Features

Help with crosshair

Scheduled Pinned Locked Moved Unsolved QML and Qt Quick
8 Posts 4 Posters 964 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.
  • B Offline
    B Offline
    BeatrizGM
    wrote on last edited by
    #1

    Crosshair.png

    Hello everyone!!
    I need to do something like image. My problem is that there is a delay between mouse and my crosshair, and I don't know how I can do it better.
    It's doing in qml wit c++

    Thanks so much

    1 Reply Last reply
    0
    • oria66O Offline
      oria66O Offline
      oria66
      wrote on last edited by
      #2

      Hi. Can you post some code?

      The truth is out there

      B 1 Reply Last reply
      0
      • oria66O oria66

        Hi. Can you post some code?

        B Offline
        B Offline
        BeatrizGM
        wrote on last edited by
        #3

        @oria66 Yes, thanks so much

        here is

           MouseArea {
                anchors.fill: parent
                hoverEnabled: true
                acceptedButtons: Qt.LeftButton | Qt.RightButton
                onPositionChanged:(mouse)=> {
                                      actualLatLon.text= geoplotModel.getMousePosition(mouse.x,mouse.y);
                                      crosshair_y_axis.x = mouse.x-2;
                                      crosshair_y_axis.y = mouse.y - crosshair_y_axis.height/2;
                                      crosshair_x_axis.x = mouse.x- crosshair_x_axis.width/2;
                                      crosshair_x_axis.y = mouse.y - 2;
                                  }
                //onPressed:(mouse)=> mouse.accepted = false
                cursorShape: Qt.CrossCursor
                onEntered: {
                    crosshair_y_axis.visible = true
                    crosshair_x_axis.visible = true
                }
        
                onPressed: (mouse) => {
                               if(mouse.button === Qt.RightButton){
                                   geoplotModel.saveRightClickPosition(mouse.x,mouse.y)
                               }
                               mouse.accepted = false;
                           }
            }
        }
        
        Rectangle{
            id: crosshair_y_axis
            height:1500
            width: 4
            color: "black"
        }
        
        Rectangle{
            id: crosshair_x_axis
            width: 2500
            height: 4
            color: "black"
        }
        
        GrecKoG 1 Reply Last reply
        0
        • B BeatrizGM

          @oria66 Yes, thanks so much

          here is

             MouseArea {
                  anchors.fill: parent
                  hoverEnabled: true
                  acceptedButtons: Qt.LeftButton | Qt.RightButton
                  onPositionChanged:(mouse)=> {
                                        actualLatLon.text= geoplotModel.getMousePosition(mouse.x,mouse.y);
                                        crosshair_y_axis.x = mouse.x-2;
                                        crosshair_y_axis.y = mouse.y - crosshair_y_axis.height/2;
                                        crosshair_x_axis.x = mouse.x- crosshair_x_axis.width/2;
                                        crosshair_x_axis.y = mouse.y - 2;
                                    }
                  //onPressed:(mouse)=> mouse.accepted = false
                  cursorShape: Qt.CrossCursor
                  onEntered: {
                      crosshair_y_axis.visible = true
                      crosshair_x_axis.visible = true
                  }
          
                  onPressed: (mouse) => {
                                 if(mouse.button === Qt.RightButton){
                                     geoplotModel.saveRightClickPosition(mouse.x,mouse.y)
                                 }
                                 mouse.accepted = false;
                             }
              }
          }
          
          Rectangle{
              id: crosshair_y_axis
              height:1500
              width: 4
              color: "black"
          }
          
          Rectangle{
              id: crosshair_x_axis
              width: 2500
              height: 4
              color: "black"
          }
          
          GrecKoG Online
          GrecKoG Online
          GrecKo
          Qt Champions 2018
          wrote on last edited by
          #4

          Unfortunately there's not much to be done, it's due to the rendering loop of Qt and the VSync of your screen.
          Here's a relevant mailing list discussion : https://lists.qt-project.org/pipermail/interest/2014-March/011692.html

          On my 50 Hz screen this issue is very noticeable, on my 144 Hz screen it is not an issue at all.

          BTW I've changed your code to be able to run it and make it simpler:

              HoverHandler {
                  onPointChanged: {
                      crosshair_x_axis.y = point.position.y - 1
                      crosshair_y_axis.x = point.position.x - 1
                  }
              }
          
              Rectangle{
                  id: crosshair_y_axis
                  height: parent.height
                  width: 3
                  color: "black"
              }
          
              Rectangle{
                  id: crosshair_x_axis
                  width: parent.width
                  height: 3
                  color: "black"
              }
          
          1 Reply Last reply
          1
          • B Offline
            B Offline
            BeatrizGM
            wrote on last edited by
            #5

            Thank you so much for your response

            johngodJ 1 Reply Last reply
            0
            • B BeatrizGM

              Thank you so much for your response

              johngodJ Offline
              johngodJ Offline
              johngod
              wrote on last edited by
              #6

              @BeatrizGM One simple hack is to hide the mouse cursor when it is in that area. If you have the crosshair you dont need the mouse to be visible, right ? And if you do, you can simulate a mouse cursor with a image at the crosshair position, the delay will be the same that the crosshair, so it will not be noticeable

              GrecKoG 1 Reply Last reply
              0
              • johngodJ johngod

                @BeatrizGM One simple hack is to hide the mouse cursor when it is in that area. If you have the crosshair you dont need the mouse to be visible, right ? And if you do, you can simulate a mouse cursor with a image at the crosshair position, the delay will be the same that the crosshair, so it will not be noticeable

                GrecKoG Online
                GrecKoG Online
                GrecKo
                Qt Champions 2018
                wrote on last edited by
                #7

                @johngod the input lag would still be there though.

                johngodJ 1 Reply Last reply
                0
                • GrecKoG GrecKo

                  @johngod the input lag would still be there though.

                  johngodJ Offline
                  johngodJ Offline
                  johngod
                  wrote on last edited by
                  #8

                  @GrecKo You are right, the lag is there. But in some use cases the lag is just visual hassle, does not interfere with the work. I work with cad software, I have a Bricscad license, afaik they use Qt for development, and the mouse is hidden in the drawing area, where the crosshair is active, the same with other cad's like Progecad and Autocad.
                  Of course in some uses cases that I am not aware, the lag can be problematic.
                  Anyway thanks for the link, I didnt have a clue why that happens. I am developing a app that has the same problem, I will now also test it in my both monitors.

                  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