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. Mouse click event has a displacement in a QOpenGLWidget
Forum Updated to NodeBB v4.3 + New Features

Mouse click event has a displacement in a QOpenGLWidget

Scheduled Pinned Locked Moved Unsolved General and Desktop
7 Posts 3 Posters 908 Views 1 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.
  • J Offline
    J Offline
    JesusM
    wrote on last edited by
    #1

    Hi, I have an application that allows the user to click over some points and It returns its color. The problem is that when I click over a point, the coordinates that the mouse event returns are a bit moved and It returns the color of the background instead.
    I have a class that inhetirs from QOpenGlWidget that implements this Mouse event and this Widget is set in a UI with some buttons. Here you have an image:
    0_1561637427513_Captura.PNG

    If I click some pixels around the point, it returns the right color of the point, so I think that the click is returning a position with is not exactly in my QOpenGlWindow, it has some displacement
    Here I show you what is happening:
    I click over a point and it returns white color:
    0_1561637878898_colorpunto.png
    Then, I click over one point of the background near the point and it returns the color of the point. Note that this only happens in that right point, not all the points around my point.
    0_1561637974146_colorfondo.png

    I think that the mouse event is returning a point considering also the margins of the window, not only the window. Any ideas?.

    Thanks.

    jsulmJ 1 Reply Last reply
    0
    • J JesusM

      Hi, I have an application that allows the user to click over some points and It returns its color. The problem is that when I click over a point, the coordinates that the mouse event returns are a bit moved and It returns the color of the background instead.
      I have a class that inhetirs from QOpenGlWidget that implements this Mouse event and this Widget is set in a UI with some buttons. Here you have an image:
      0_1561637427513_Captura.PNG

      If I click some pixels around the point, it returns the right color of the point, so I think that the click is returning a position with is not exactly in my QOpenGlWindow, it has some displacement
      Here I show you what is happening:
      I click over a point and it returns white color:
      0_1561637878898_colorpunto.png
      Then, I click over one point of the background near the point and it returns the color of the point. Note that this only happens in that right point, not all the points around my point.
      0_1561637974146_colorfondo.png

      I think that the mouse event is returning a point considering also the margins of the window, not only the window. Any ideas?.

      Thanks.

      jsulmJ Offline
      jsulmJ Offline
      jsulm
      Lifetime Qt Champion
      wrote on last edited by
      #2

      @JesusM Use https://doc.qt.io/qt-5/qmouseevent.html#localPos instead of windowPos()

      https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      2
      • J Offline
        J Offline
        JesusM
        wrote on last edited by
        #3

        I've just tried it but I get the same trouble. Once I get the x and y values, I do glReadPixels to check the colour under this position. When the cursor is near the margins of the window I get the colour of the margins instead of white.
        0_1561652583348_color margen.png
        It occurs the same on top, left and right margins.
        I am using a layout to place the qopenglwidget on the ui.

        1 Reply Last reply
        0
        • Christian EhrlicherC Online
          Christian EhrlicherC Online
          Christian Ehrlicher
          Lifetime Qt Champion
          wrote on last edited by
          #4

          Where do you catch the mouse event?

          Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
          Visit the Qt Academy at https://academy.qt.io/catalog

          J 1 Reply Last reply
          0
          • Christian EhrlicherC Christian Ehrlicher

            Where do you catch the mouse event?

            J Offline
            J Offline
            JesusM
            wrote on last edited by
            #5

            @Christian-Ehrlicher in glwindow which is the class that inherits from QOpenGLWidget and creates the window.

             bool glwindow::eventFilter(QObject *obj, QEvent *event)
            

            and in my interface class I do this:

            QSurfaceFormat format;
                format.setDepthBufferSize(24);
                format.setStencilBufferSize(8);
                format.setVersion(4, 1);
                format.setProfile(QSurfaceFormat::CoreProfile);
                QSurfaceFormat::setDefaultFormat(format);
            
                glwindow *ventana = new glwindow();
                ventana->setFormat(format);
                ventana->show();
                std::cout<<"Ventana lanzada"<<std::endl;
                ventana->setMouseTracking(true);
                ventana->installEventFilter(ventana);
                ventana->setSizePolicy(QSizePolicy::MinimumExpanding,QSizePolicy::Expanding);
                this->ventana = ventana;
                ui->gridLayout->addWidget(ventana,0,0);
            
            1 Reply Last reply
            0
            • Christian EhrlicherC Online
              Christian EhrlicherC Online
              Christian Ehrlicher
              Lifetime Qt Champion
              wrote on last edited by
              #6

              I'm not sure but do the corrdinates match to the main windgets coordinates? Did you check by e.g. overwriting mouseMoveEvent() on the main window?

              Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
              Visit the Qt Academy at https://academy.qt.io/catalog

              1 Reply Last reply
              0
              • J Offline
                J Offline
                JesusM
                wrote on last edited by JesusM
                #7

                @Christian-Ehrlicher mouseMoveEvent is a QWidget function, so what do you mean, the openGLWidget or the main window where the widget is placed?

                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