Left Mouse press click not generated



  • HI,
    I Have an application in which i want to capture the coordinates of mouse when i clicked mouse's left button. But its not working for left click while its working fine for right button. My mousePressEvent implementation is as follow:
    @
    void MyClassName::mousePressEvent(QMouseEvent *event)
    {
    qDebug()<<"x->"<<event->pos().x()<<", y->"<<event->pos().y();

    }@

    with this code if i click right buttn position of x & y get displayed but not in case of left click because mousePressEvent(QMouseEvent *event) not getting hit.

    So please give me suggestion for that

    Rgds
    Pardeep Sharma



  • Does your object contains any other sub widgets? If so, maybe one of them is already handling left clicks, so consumes the event, but ignore right clicks.



  • Hi Pardeep Sharma,

    Use this code in ::mousePressEvent(QMouseEvent *event)

    it works only if left mouse button is down

    if (event->button() == Qt::LeftButton) {
        // **left click code**....
    }

Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.