Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. QGLWidget mouse movement tracking
Qt 6.11 is out! See what's new in the release blog

QGLWidget mouse movement tracking

Scheduled Pinned Locked Moved Unsolved General and Desktop
13 Posts 3 Posters 4.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.
  • mrjjM Offline
    mrjjM Offline
    mrjj
    Lifetime Qt Champion
    wrote on last edited by mrjj
    #2

    Hi
    Like this ?
    https://stackoverflow.com/questions/18542901/getting-mouse-coordinates-qt-opengl

    1 Reply Last reply
    2
    • JKSHJ Offline
      JKSHJ Offline
      JKSH
      Moderators
      wrote on last edited by
      #3

      @s002wjh I recommend using QOpenGLWidget instead. QGLWidget is deprecated.

      Qt Doc Search for browsers: forum.qt.io/topic/35616/web-browser-extension-for-improved-doc-searches

      S 1 Reply Last reply
      2
      • JKSHJ JKSH

        @s002wjh I recommend using QOpenGLWidget instead. QGLWidget is deprecated.

        S Offline
        S Offline
        s002wjh
        wrote on last edited by s002wjh
        #4

        @JKSH

        ok thanks. i assume QT mousePressEvent or mousemoveevent function can be used in QTopenGLwidget class.

        also using mouseevent, if i click the button, how do i display the x,y at the pointer of my mouse.

        is there mouseClickEvent?

        mrjjM 1 Reply Last reply
        0
        • S s002wjh

          @JKSH

          ok thanks. i assume QT mousePressEvent or mousemoveevent function can be used in QTopenGLwidget class.

          also using mouseevent, if i click the button, how do i display the x,y at the pointer of my mouse.

          is there mouseClickEvent?

          mrjjM Offline
          mrjjM Offline
          mrjj
          Lifetime Qt Champion
          wrote on last edited by
          #5

          Hi
          yes, QOpenGLWidget is also a QWidget and offer same virtual functions to override.
          mouseClickEvent = mousePressEvent.

          • also using mouseevent, if i click the button, how do i display the x,y at the pointer of my mouse.

          Do you mean the mouse position over the button
          or do you mean the global mouse position at that moment ?
          Note there is also
          QPoint globalCursorPos = QCursor::pos();
          to ask where mouse is in global coordinates.
          You can call that from any function and no need for subclassing.
          In mousePress, the pos you get there is translated to the local coordinates system.
          Very useful if you want to draw on the widget etc.

          So it really depends on what you really want to archive ?

          S 1 Reply Last reply
          1
          • mrjjM mrjj

            Hi
            yes, QOpenGLWidget is also a QWidget and offer same virtual functions to override.
            mouseClickEvent = mousePressEvent.

            • also using mouseevent, if i click the button, how do i display the x,y at the pointer of my mouse.

            Do you mean the mouse position over the button
            or do you mean the global mouse position at that moment ?
            Note there is also
            QPoint globalCursorPos = QCursor::pos();
            to ask where mouse is in global coordinates.
            You can call that from any function and no need for subclassing.
            In mousePress, the pos you get there is translated to the local coordinates system.
            Very useful if you want to draw on the widget etc.

            So it really depends on what you really want to archive ?

            S Offline
            S Offline
            s002wjh
            wrote on last edited by
            #6

            @mrjj

            hi i like to display text of X,Y coordinate when my mouse is clicked within the GUI.

            for example if my mouse arrow position currently is x=5, y=6. i like to settext so it dispaly 5,6 at coordinate 5,6.

            such as
            0_1522870388713_test.png

            mrjjM 1 Reply Last reply
            0
            • S s002wjh

              @mrjj

              hi i like to display text of X,Y coordinate when my mouse is clicked within the GUI.

              for example if my mouse arrow position currently is x=5, y=6. i like to settext so it dispaly 5,6 at coordinate 5,6.

              such as
              0_1522870388713_test.png

              mrjjM Offline
              mrjjM Offline
              mrjj
              Lifetime Qt Champion
              wrote on last edited by
              #7

              @s002wjh
              Ok, in that case you want the local coordinates and mousePress is the way to go.

              S 1 Reply Last reply
              0
              • mrjjM mrjj

                @s002wjh
                Ok, in that case you want the local coordinates and mousePress is the way to go.

                S Offline
                S Offline
                s002wjh
                wrote on last edited by
                #8

                @mrjj
                yes i got that but do i use qlabel, setText and setposition and setfont to display the coordinate or there are better way to do it.

                mrjjM 1 Reply Last reply
                0
                • S s002wjh

                  @mrjj
                  yes i got that but do i use qlabel, setText and setposition and setfont to display the coordinate or there are better way to do it.

                  mrjjM Offline
                  mrjjM Offline
                  mrjj
                  Lifetime Qt Champion
                  wrote on last edited by
                  #9

                  @s002wjh
                  Hi
                  It really depends on what you already have.
                  If you draw the graphs looking thing in the image, you could also just
                  store the values in variables and draw it as part of the graphs.
                  Else a Label is not super bad but might not be optimal if you say resize the window etc as
                  the labels stay in same position.

                  S 1 Reply Last reply
                  0
                  • mrjjM mrjj

                    @s002wjh
                    Hi
                    It really depends on what you already have.
                    If you draw the graphs looking thing in the image, you could also just
                    store the values in variables and draw it as part of the graphs.
                    Else a Label is not super bad but might not be optimal if you say resize the window etc as
                    the labels stay in same position.

                    S Offline
                    S Offline
                    s002wjh
                    wrote on last edited by s002wjh
                    #10

                    @mrjj
                    so i do have the location of mouse stored using mouseevent, but not sure best way to draw that text since its QGLwidget.
                    so maybe something like Qpainter drawtext?

                    mrjjM 1 Reply Last reply
                    0
                    • S s002wjh

                      @mrjj
                      so i do have the location of mouse stored using mouseevent, but not sure best way to draw that text since its QGLwidget.
                      so maybe something like Qpainter drawtext?

                      mrjjM Offline
                      mrjjM Offline
                      mrjj
                      Lifetime Qt Champion
                      wrote on last edited by
                      #11

                      Hi
                      yeah something like
                      https://het.as.utexas.edu/HET/Software/html/opengl-overpainting.html

                      But i do wonder. how do you draw that graph look ? is that openGL?

                      S 1 Reply Last reply
                      0
                      • mrjjM mrjj

                        Hi
                        yeah something like
                        https://het.as.utexas.edu/HET/Software/html/opengl-overpainting.html

                        But i do wonder. how do you draw that graph look ? is that openGL?

                        S Offline
                        S Offline
                        s002wjh
                        wrote on last edited by
                        #12

                        @mrjj
                        yes its openGL stuff, i didn't wrote the code, all the stuff i done is use the qpainter. so not sure even qpainter would work.

                        mrjjM 1 Reply Last reply
                        0
                        • S s002wjh

                          @mrjj
                          yes its openGL stuff, i didn't wrote the code, all the stuff i done is use the qpainter. so not sure even qpainter would work.

                          mrjjM Offline
                          mrjjM Offline
                          mrjj
                          Lifetime Qt Champion
                          wrote on last edited by
                          #13

                          @s002wjh
                          Well you can use QPainter as links shows.
                          Its 4.8 and the older openGL widget but should work the same in later classes.

                          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