From 7a89aee0bbdc2445c82380a13c9852ff579dfa30 Mon Sep 17 00:00:00 2001 From: Magne Sjaastad Date: Fri, 24 Mar 2017 22:40:57 +0100 Subject: [PATCH] #1296 Multiselect in property panel lists using ctrl-click is vulnerable to mouse drag --- .../cafUserInterface/cafPdmUiListEditor.cpp | 28 +++++++++++++++++-- 1 file changed, 26 insertions(+), 2 deletions(-) diff --git a/Fwk/AppFwk/cafUserInterface/cafPdmUiListEditor.cpp b/Fwk/AppFwk/cafUserInterface/cafPdmUiListEditor.cpp index b0f8af841f..4e1585b9a6 100644 --- a/Fwk/AppFwk/cafUserInterface/cafPdmUiListEditor.cpp +++ b/Fwk/AppFwk/cafUserInterface/cafPdmUiListEditor.cpp @@ -243,8 +243,13 @@ QWidget* PdmUiListEditor::createEditorWidget(QWidget * parent) connect(m_listView->selectionModel(), SIGNAL(selectionChanged(const QItemSelection&, const QItemSelection& )), this, SLOT(slotSelectionChanged(const QItemSelection&, const QItemSelection& ))); connect(m_model, SIGNAL(dataChanged(const QModelIndex&, const QModelIndex&)), this, SLOT(slotListItemEdited(const QModelIndex&, const QModelIndex&))); + + // Used to track key press m_listView->installEventFilter(this); + // Used to track mouse events + m_listView->viewport()->installEventFilter(this); + return m_listView; } @@ -370,9 +375,28 @@ void PdmUiListEditor::pasteFromString(const QString& content) //-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- -bool PdmUiListEditor::eventFilter(QObject * listView, QEvent * event) +bool PdmUiListEditor::eventFilter(QObject* object, QEvent * event) { - if (listView == m_listView && event->type() == QEvent::KeyPress) + if (object == m_listView->viewport() && event->type() == QEvent::MouseMove) + { + QMouseEvent* mouseEvent = dynamic_cast(event); + if (mouseEvent) + { + if (mouseEvent->buttons() & Qt::LeftButton + && mouseEvent->modifiers() & Qt::ControlModifier) + { + // When Ctrl button is pressed, left mouse button is pressed, and the mouse is moving, + // a possible bug in Qt is observed causing the selection to end up with single item selection + // When returning here without doing anything, system behaves as expected + + // NOTE: The mouse event is handled by the viewport() of the list view, not the list view itself + + return true; + } + } + } + + if (object == m_listView && event->type() == QEvent::KeyPress) { if (m_optionsOnly) return false; CAF_ASSERT(m_options.isEmpty()); // Not supported yet