forked from qt-creator/qt-creator
QmlDesigner: Block starting drag when clicking on non-draggable node
Fixes: QDS-6415 Change-Id: I328e7715d2837d1126506a6fbbf4d1bf52cc250f Reviewed-by: Thomas Hartmann <thomas.hartmann@qt.io> Reviewed-by: Mahmoud Badri <mahmoud.badri@qt.io> Reviewed-by: <github-actions-qt-creator@cristianadam.eu>
This commit is contained in:
@@ -281,4 +281,20 @@ bool NavigatorTreeView::viewportEvent(QEvent *event)
|
||||
return QTreeView::viewportEvent(event);
|
||||
}
|
||||
|
||||
void NavigatorTreeView::mousePressEvent(QMouseEvent *event)
|
||||
{
|
||||
// Block drag from starting if press was on an item that is not draggable.
|
||||
// This is necessary as it is the selected items that are dragged and the pressed item may not
|
||||
// be a selected item, e.g. when pressing on locked item, leading to unexpected drags.
|
||||
m_dragAllowed = model()->flags(indexAt(event->pos())) & Qt::ItemIsDragEnabled;
|
||||
|
||||
QTreeView::mousePressEvent(event);
|
||||
}
|
||||
|
||||
void NavigatorTreeView::startDrag(Qt::DropActions supportedActions)
|
||||
{
|
||||
if (m_dragAllowed)
|
||||
QTreeView::startDrag(supportedActions);
|
||||
}
|
||||
|
||||
}
|
||||
|
@@ -40,8 +40,13 @@ public:
|
||||
static void drawSelectionBackground(QPainter *painter, const QStyleOption &option);
|
||||
bool viewportEvent(QEvent *event) override;
|
||||
|
||||
protected:
|
||||
void mousePressEvent(QMouseEvent *event) override;
|
||||
void startDrag(Qt::DropActions supportedActions) override;
|
||||
|
||||
private:
|
||||
PreviewToolTip *m_previewToolTip = nullptr;
|
||||
qint32 m_previewToolTipNodeId = -1;
|
||||
bool m_dragAllowed = true;
|
||||
};
|
||||
}
|
||||
|
Reference in New Issue
Block a user