我从QQuickPaintedItem
派生了一个课程,其中我要处理mousePressEvent
和mouseReleasEvent
(以及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);
}