我正在继承 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;
};