0

I am currently having a conflict between my paintGL() and my QPaintEvent function. I am trying to render a line that acts as a measuring tool to use on objects drawn in the paintGL(), however my current implementation renders a blank screen and I can't seem to figure out the problem. I've also tried placing the code from inside the paintEvent into the paintGL, this renders the objects inisde the paintGL but the line to be drawn from the QPainter does not work.

This is my paintEvent()

void Widget::paintEvent(QPaintEvent* e)
{
    if (drawLine) {

        QPainter painter(this);
        QPen paintpen(Qt::red);
        paintpen.setWidth(4);

        QPen linepen(Qt::black);
        linepen.setWidth(4);

        QPoint p1;
        p1.setX(xAtPress);
        p1.setY(yAtPress);

        painter.setPen(paintpen);
        painter.drawPoint(p1);

        QPoint p2;
        p2.setX(xAtRelease);
        p2.setY(yAtRelease);

        painter.setPen(paintpen);
        painter.drawPoint(p2);

        painter.setPen(linepen);
        painter.drawLine(p1, p2);

    }   
}

This is my paintGL()

 void Widget::paintGL()
    {
        // Clear the color and depth buffer with specified clear colour.
        // This will replace everything that was in the previous frame with the clear colour.
        glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

        test0->draw();
        test1->draw();
        test2->draw();

        }

    }
  • FYI: [SO: Paint a rect on qglwidget at specifit times](https://stackoverflow.com/a/42420804/7478597) (It's about head-up display rendering with `QPainter`.) – Scheff's Cat Jan 10 '20 at 06:42
  • FYI: [SO: When to use paintEvent and paintGL in Qt?](https://stackoverflow.com/a/50857712/7478597) about the relation of `paintEvent()` and `paintGL()`. – Scheff's Cat Jan 10 '20 at 06:44
  • @Scheff I read both posts and yet my implementation does not work unfortunately – testStackFlow Jan 10 '20 at 16:46

0 Answers0