Proper sub-widget mouse grabbing in QWidgetWindow.

This commit is contained in:
Samuel Rødal 2011-05-04 10:42:54 +02:00
parent 07fef33d28
commit c418f5ce8d
2 changed files with 8 additions and 1 deletions

View File

@ -91,13 +91,19 @@ bool QWidgetWindow::event(QEvent *event)
void QWidgetWindow::handleMouseEvent(QMouseEvent *event)
{
// which child should have it?
QWidget *widget = m_widget->childAt(event->pos());
QWidget *widget = m_implicit_mouse_grabber ? m_implicit_mouse_grabber.data() : m_widget->childAt(event->pos());
// TODO: make sure mouse release is delivered to same widget that got the press event
if (!widget)
widget = m_widget;
if (event->type() == QEvent::MouseButtonPress && !m_implicit_mouse_grabber)
m_implicit_mouse_grabber = widget;
if (event->buttons() == Qt::NoButton)
m_implicit_mouse_grabber.clear();
QPoint mapped = widget->mapFrom(m_widget, event->pos());
QMouseEvent translated(event->type(), mapped, event->globalPos(), event->button(), event->buttons(), event->modifiers());

View File

@ -72,6 +72,7 @@ protected:
private:
QWidget *m_widget;
QWeakPointer<QWidget> m_implicit_mouse_grabber;
};
QT_END_NAMESPACE