鼠标按下判断左键\右键
void mousePressEvent(QMouseEvent* event) { if (event->button() == Qt::MouseButton::LeftButton) { ui.lineEdit_LeftOrRight->setText("LeftButton"); } if (event->button() == Qt::MouseButton::RightButton) { ui.lineEdit_LeftOrRight->setText("RightButton"); } }
鼠标移动实时显示坐标位置
void mouseMoveEvent(QMouseEvent* event) { ui.lineEdit_x->setText(QString::number(event->x())); ui.lineEdit_y->setText(QString::number(event->y())); }
鼠标释放后打印释放位置
void mouseReleaseEvent(QMouseEvent* event) { qDebug() << event->x(); qDebug() << event->y(); }