QOpenGLWidget draw line sometimes invisible or bold

318 Views Asked by At

I'm subclassing QOpenGLWidget for drawing a crosshair follow mouse. But drawing in QOpenGLWidget is little weird. The horizontal line could disappear or be bold in some height while I moving the mouse up and down. The problem won't appeare in QWidget,Why?

class OpenGLWidget : public QOpenGLWidget {
 public:
  OpenGLWidget(QWidget *parent = nullptr) : QOpenGLWidget(parent) {
    setMouseTracking(true);
  }
  void mouseMoveEvent(QMouseEvent *event) {
    m_mousePoint = event->pos();
    update();
  }
  void paintGL() {
    QPainter p(this);
    p.setPen(Qt::white);
    p.drawLine(QLineF(0, m_mousePoint.y(), width(), m_mousePoint.y()));
    p.drawLine(QLineF(m_mousePoint.x(), 0, m_mousePoint.x(), height()));
  }

  QPointF m_mousePoint;
};

the horizontal line looks bold
the horizontal line disapeared here

0

There are 0 best solutions below