void MyWidget::mousePressEvent(QMouseEvent *event) { if (event->button() == Qt::LeftButton) { qDebug() << "Left mouse button pressed"; } }
void MyWidget::mouseMoveEvent(QMouseEvent *event) { QPoint pos = event->pos(); qDebug() << "Mouse moved to position: " << pos.x() << "," << pos.y(); }This code example shows how to handle mouse movement events in a custom widget. When the mouse moves, the current position is retrieved from the event and printed to the console. Package library: Qt Framework