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. Best way to redraw or repaint a QOpenGLWidget for Qt5 c++
Forum Updated to NodeBB v4.3 + New Features

Best way to redraw or repaint a QOpenGLWidget for Qt5 c++

Scheduled Pinned Locked Moved Unsolved General and Desktop
5 Posts 2 Posters 2.0k 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.
  • A Offline
    A Offline
    AprilF8
    wrote on last edited by
    #1

    Hi,

    I am having some issues with wrapping my head around the best way to repaint or redraw my QOpenGLWidget in my mainwindow.

    As of now I want to move a certain "target" object around my QOpenGLWidget by manipulating the (x, y) coordinates. Every time I change the targets coordinates I would like to redraw where the target is and that is it. In my current program I am working on I use the update() function but it doesn't seem to be consistent in the redraw and only will redraw once.

    What is the best, most efficient way to redraw my widget multiple times in my mainwindow.

    Thanks!

    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi,

      From the looks of it the Hello GL2 example might be of interest.

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      A 2 Replies Last reply
      0
      • SGaistS SGaist

        Hi,

        From the looks of it the Hello GL2 example might be of interest.

        A Offline
        A Offline
        AprilF8
        wrote on last edited by
        #3

        @SGaist Thank you! This helps a lot!

        1 Reply Last reply
        0
        • SGaistS SGaist

          Hi,

          From the looks of it the Hello GL2 example might be of interest.

          A Offline
          A Offline
          AprilF8
          wrote on last edited by
          #4

          @SGaist I was just wondering, I noticed that when I hook up my debugger to the Hello GL2 example.. It looks like the paintGL() function is called or triggered when a mouse even occurs over the slider widget.

          I am assuming it is called when either of these functions signal is released. Is there a way to trigger the paintGL() function with a Qtimer? Or do you know of an example I can look at?

          void GLWidget::mousePressEvent(QMouseEvent *event)
          {
              m_lastPos = event->pos();
          }
          
          void GLWidget::mouseMoveEvent(QMouseEvent *event)
          {
              int dx = event->x() - m_lastPos.x();
              int dy = event->y() - m_lastPos.y();
          
              if (event->buttons() & Qt::LeftButton) {
                  setXRotation(m_xRot + 8 * dy);
                  setYRotation(m_yRot + 8 * dx);
              } else if (event->buttons() & Qt::RightButton) {
                  setXRotation(m_xRot + 8 * dy);
                  setZRotation(m_zRot + 8 * dx);
              }
              m_lastPos = event->pos();
          }
          
          void Window::keyPressEvent(QKeyEvent *e)
          {
              if (e->key() == Qt::Key_Escape)
                  close();
              else
                  QWidget::keyPressEvent(e);
          }
          
          1 Reply Last reply
          0
          • SGaistS Offline
            SGaistS Offline
            SGaist
            Lifetime Qt Champion
            wrote on last edited by SGaist
            #5

            IIRC, you can connect the QTimer to the update slot of your widget.

            It's not the mouse itself. When you move a slider, the corresponding properties of the GLWidget object are changed and a call to update is done at the end of the slot.

            Interested in AI ? www.idiap.ch
            Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

            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