我将QOpenGLWidget子类化,以绘制十字准线跟随鼠标。但是在QOpenGLWidget中进行绘制有点奇怪。当我上下移动鼠标时,水平线可能会消失或在某些高度上变为粗体。问题不会出现在QWidget中,为什么?
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