void ViewWidget::keyReleaseEvent(QKeyEvent *event)
{
// Update mouse_modifiers_ also if modifiers change, but pointer doesn't move
- if (mouse_point_.x() >= 0 && mouse_point_.y() >= 0) // mouse is inside
+ if ((mouse_point_.x() >= 0) && (mouse_point_.y() >= 0)) // mouse is inside
mouse_modifiers_ = event->modifiers();
update();
}
void ViewWidget::keyPressEvent(QKeyEvent *event)
{
// Update mouse_modifiers_ also if modifiers change, but pointer doesn't move
- if (mouse_point_.x() >= 0 && mouse_point_.y() >= 0) // mouse is inside
+ if ((mouse_point_.x() >= 0) && (mouse_point_.y() >= 0)) // mouse is inside
mouse_modifiers_ = event->modifiers();
update();
}
drag_items(event->pos() - mouse_down_point_);
}
}
+
+ // Force a repaint of the widget to update highlighted parts
+ update();
}
void ViewWidget::leaveEvent(QEvent*)
{
- mouse_point_ = QPoint(-1, -1);
+ bool cursor_above_widget = rect().contains(mapFromGlobal(QCursor::pos()));
+
+ // We receive leaveEvent also when the widget loses focus even when
+ // the mouse cursor hasn't moved at all - e.g. when the popup shows.
+ // However, we don't want to reset mouse_position_ when the mouse is
+ // still above this widget as doing so would break the context menu
+ if (!cursor_above_widget)
+ mouse_point_ = QPoint(INT_MIN, INT_MIN);
+
mouse_modifiers_ = Qt::NoModifier;
item_hover(nullptr, QPoint());
+
update();
}