mardi 21 avril 2015

QQuickPaintedItem mouseReleaseEvent gets only called after doubleclick

I've derived a class from QQuickPaintedItem in which I want to handle the mousePressEvent and the mouseReleasEvent (and also the mouseMoveEvent but that is not my prolem now).

The mousePressEvent gets called properly everytime the left mouse button is pressed. But the mouseReleaseEvent gets only called after a double click. What I expected is to get the event everytime the button is released. How can I change this?

This is what I do:

MyView::MyView(QQuickItem *parent):
    QQuickPaintedItem(parent)
{
    setAcceptedMouseButtons(Qt::LeftButton);
}

void MyView::mousePressEvent(QMouseEvent *evt)
{
    //gets called after every single mouse click
    qDebug("mousePressEvent");
    if(evt->button() == Qt::LeftButton)
    {
        //do something...
        evt->accept();
    }
    else
    {
        evt->ignore();
    }
    QQuickPaintedItem::mousePressEvent(evt);
}

void MyView::mouseReleaseEvent(QMouseEvent *evt)
{
    //gets only called when releasing the mouse button after a double click
    qDebug("mouseReleaseEvent");
    if(evt->button() == Qt::LeftButton)
    {
        //do something...
        evt->accept();
    }
    else
    {
        evt->ignore();
    }
    QQuickPaintedItem::mouseReleaseEvent(evt);
}

Aucun commentaire:

Enregistrer un commentaire