// Inside a mousePressEvent(QMouseEvent *event) function if (event->button() == Qt::LeftButton) { // Code to execute when left button is pressed }
// Inside a mouseReleaseEvent(QMouseEvent *event) function if (event->button() == Qt::RightButton) { // Code to execute when right button is released }
// Inside a mouseDoubleClickEvent(QMouseEvent *event) function if (event->button() == Qt::MiddleButton) { // Code to execute when middle button is double-clicked }The examples above demonstrate how to use the QMouseEvent buttons to determine which mouse button was pressed or released, and perform certain actions depending on which button was used. The Qt library contains the QMouseEvent class, along with other classes for handling events in a Qt application.