QQuickPaintedItem mouseReleaseEvent仅在doubleclick后调用

时间:2015-04-21 12:51:25

标签: qt

我从QQuickPaintedItem派生了一个课程,其中我要处理mousePressEventmouseReleasEvent(以及mouseMoveEvent,但现在不是我的问题)。

每次按下鼠标左键都会正确调用mousePressEvent。但mouseReleaseEvent仅在双击后才会被调用。我期望的是每次释放按钮时都能获得该事件。我怎么能改变这个?

这就是我的所作所为:

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);
}

0 个答案:

没有答案