diff options
author | Alexis Menard <alexis.menard@nokia.com> | 2009-10-08 14:06:12 (GMT) |
---|---|---|
committer | Alexis Menard <alexis.menard@nokia.com> | 2009-10-08 14:06:12 (GMT) |
commit | 0054b444a202d08167c49a1a94fd2d306d14f91f (patch) | |
tree | b10f1377906dbff9f8b6d7383be88a176086698c /src | |
parent | 922cf20905d829d1a4ec9205beacbee27efe35f8 (diff) | |
download | Qt-0054b444a202d08167c49a1a94fd2d306d14f91f.zip Qt-0054b444a202d08167c49a1a94fd2d306d14f91f.tar.gz Qt-0054b444a202d08167c49a1a94fd2d306d14f91f.tar.bz2 |
Fix context menu and menu key in QGraphicsView.
This fixes a weird bug when pressing the menu key on a proxy that
embed a lineedit (but the proxy don't have the focus).
At each time the key was pressed a context menu was created. When we press
the menu key, QWidgetMapper will create a context menu event that will be
sent to the QGraphicsView and will end up in QGraphicsScene.
QGraphicsScene will then try to find all items under the mouse and will
try to find any item from this list that accept this contextMenuEvent.
In our case the proxy will always accept it and therefor will always send
it to the widget that it owns and that's why we had this infinite numbers
of QMenu. In QWidget world the context menu event is always sent to the
widget that has the focus. If you checked any QWidget subclasses you'll
see that all of them assume that when they get a context menu event
everything is fine focus wise. We could have changed
QGraphicsScene::contextMenuEvent but this will breaks some existing code.
Instead we just checked that QGraphicsProxyWidget has the focus
before we actually send the contextMenuEvent to the widget it owns.
I have modified an existing auto-test to cover that. Be careful
widget->setContextMenuPolicy(Qt::ActionsContextMenu) means that you will
get no contextMenuEvent. :D. In this test i cover the standard use case
and the one with Qt::ActionsContextMenu with and without the focus on the
proxy.
Task-number:QTBUG-3787
Reviewed-by:jan-arve
Diffstat (limited to 'src')
-rw-r--r-- | src/gui/graphicsview/qgraphicsproxywidget.cpp | 2 |
1 files changed, 1 insertions, 1 deletions
diff --git a/src/gui/graphicsview/qgraphicsproxywidget.cpp b/src/gui/graphicsview/qgraphicsproxywidget.cpp index 15b9ff3..b7a3962 100644 --- a/src/gui/graphicsview/qgraphicsproxywidget.cpp +++ b/src/gui/graphicsview/qgraphicsproxywidget.cpp @@ -973,7 +973,7 @@ void QGraphicsProxyWidget::hideEvent(QHideEvent *event) void QGraphicsProxyWidget::contextMenuEvent(QGraphicsSceneContextMenuEvent *event) { Q_D(QGraphicsProxyWidget); - if (!event || !d->widget || !d->widget->isVisible()) + if (!event || !d->widget || !d->widget->isVisible() || !hasFocus()) return; // Find widget position and receiver. |