How I can use a "Mouse Leave" event inside QItemDelegate::editorEvent ?
I'm using this code, but the editorEvent doesn't called in a "leave" event.
And the mouse move don't capture events outside the item rect
Code:
bool DownloadItemDelegate::editorEvent(
const QStyleOptionViewItem& option,
{
if (event
->type
() == QEvent::MouseButtonPress) {
if (index.data(Qt::UserRole).toRect().contains(e->pos())) // button "resume"
{
model->setData(index, true, Qt::UserRole + 1); // button pressed (visual-only | button style = sunken)
model->setData(index, true, Qt::UserRole + 2); // button pressed (is clicked?)
return true;
}
}
else if (event
->type
() == QEvent::MouseButtonRelease) {
if (index.data(Qt::UserRole).toRect().contains(e->pos()))
{
model->setData(index, false, Qt::UserRole + 1); // button style = enabled
if (index.data(Qt::UserRole + 2).toBool()) // is clicked == true | emit resume();
{
//emit resume_pressed;
}
return true;
}
model->setData(index, false, Qt::UserRole + 2); // clear this flag
}
else if (event
->type
() == QEvent::MouseMove) {
if (!index.data(Qt::UserRole).toRect().contains(e->pos())) // if exit button rect, button style = enabled
{
model->setData(index, false, Qt::UserRole + 1);
return true;
}
else if (index.data(Qt::UserRole + 2).toBool()) // if enter button rect, and, the checked flag is true, button style = sunken
{
model->setData(index, true, Qt::UserRole + 1);
return true;
}
}
return false;
}
This handles the basics of a QPushButton that I need, but, how can I check if the mouse leave the item region ?
I need to check this event to clear the flags of the button.
Re: How I can use a "Mouse Leave" event inside QItemDelegate::editorEvent ?
You will not catch a leaveEvent this way as the cursor is not over the item anymore so a different item will start receiving events. That's your clue that the cursor has left the item.
Re: How I can use a "Mouse Leave" event inside QItemDelegate::editorEvent ?
So, the solution is to remove the pressed flag from the event function of all other widgets, when they get an event? Does not seem right.
Re: How I can use a "Mouse Leave" event inside QItemDelegate::editorEvent ?
with the MouseOver option flag like described here it works: http://www.qtcentre.org/threads/1314...te-enter-event