diff --git a/share/qtcreator/qmldesigner/itemLibraryQmlSources/ItemsView.qml b/share/qtcreator/qmldesigner/itemLibraryQmlSources/ItemsView.qml index c523fb7b702..16a7ca8f7ea 100644 --- a/share/qtcreator/qmldesigner/itemLibraryQmlSources/ItemsView.qml +++ b/share/qtcreator/qmldesigner/itemLibraryQmlSources/ItemsView.qml @@ -235,7 +235,7 @@ Item { id: verticalScrollView anchors.fill: parent clip: true - interactive: !itemContextMenu.opened && !moduleContextMenu.opened + interactive: !itemContextMenu.opened && !moduleContextMenu.opened && !rootView.isDragging onContentHeightChanged: { var maxPosition = Math.max(contentHeight - verticalScrollView.height, 0) @@ -352,7 +352,7 @@ Item { width: 270 height: parent.height clip: true - interactive: !itemContextMenu.opened && !moduleContextMenu.opened + interactive: !itemContextMenu.opened && !moduleContextMenu.opened && !rootView.isDragging onContentHeightChanged: { var maxPosition = Math.max(contentHeight - horizontalScrollView.height, 0) @@ -457,6 +457,8 @@ Item { id: itemScrollView width: itemsView.width - 275 height: itemsView.height + interactive: !itemContextMenu.opened && !moduleContextMenu.opened && !rootView.isDragging + onContentHeightChanged: { var maxPosition = Math.max(contentHeight - itemScrollView.height, 0) if (contentY > maxPosition) diff --git a/src/plugins/qmldesigner/components/itemlibrary/itemlibrarywidget.cpp b/src/plugins/qmldesigner/components/itemlibrary/itemlibrarywidget.cpp index ae2c88f5b6f..484cd1c28a9 100644 --- a/src/plugins/qmldesigner/components/itemlibrary/itemlibrarywidget.cpp +++ b/src/plugins/qmldesigner/components/itemlibrary/itemlibrarywidget.cpp @@ -105,6 +105,10 @@ bool ItemLibraryWidget::eventFilter(QObject *obj, QEvent *event) m_itemToDrag = {}; } } + } else if (event->type() == QMouseEvent::MouseButtonRelease) { + m_itemToDrag = {}; + + setIsDragging(false); } return QObject::eventFilter(obj, event); @@ -366,12 +370,21 @@ void ItemLibraryWidget::handlePriorityImportsChanged() } } +void ItemLibraryWidget::setIsDragging(bool val) +{ + if (m_isDragging != val) { + m_isDragging = val; + emit isDraggingChanged(); + } +} + void ItemLibraryWidget::startDragAndDrop(const QVariant &itemLibEntry, const QPointF &mousePos) { // Actual drag is created after mouse has moved to avoid a QDrag bug that causes drag to stay // active (and blocks mouse release) if mouse is released at the same spot of the drag start. m_itemToDrag = itemLibEntry; m_dragStartPoint = mousePos.toPoint(); + setIsDragging(true); } bool ItemLibraryWidget::subCompEditMode() const diff --git a/src/plugins/qmldesigner/components/itemlibrary/itemlibrarywidget.h b/src/plugins/qmldesigner/components/itemlibrary/itemlibrarywidget.h index 16673849be5..b3134c80513 100644 --- a/src/plugins/qmldesigner/components/itemlibrary/itemlibrarywidget.h +++ b/src/plugins/qmldesigner/components/itemlibrary/itemlibrarywidget.h @@ -44,6 +44,9 @@ class ItemLibraryWidget : public QFrame public: Q_PROPERTY(bool subCompEditMode READ subCompEditMode NOTIFY subCompEditModeChanged) + // Needed for a workaround for a bug where after drag-n-dropping an item, the ScrollView scrolls to a random position + Q_PROPERTY(bool isDragging MEMBER m_isDragging NOTIFY isDraggingChanged) + ItemLibraryWidget(AsynchronousImageCache &imageCache); ~ItemLibraryWidget(); @@ -76,6 +79,7 @@ public: signals: void itemActivated(const QString &itemName); void subCompEditModeChanged(); + void isDraggingChanged(); protected: bool eventFilter(QObject *obj, QEvent *event) override; @@ -86,6 +90,8 @@ private: void updateSearch(); void handlePriorityImportsChanged(); + void setIsDragging(bool val); + static QString getDependencyImport(const Import &import); QTimer m_compressionTimer; @@ -107,6 +113,7 @@ private: QString m_filterText; QPoint m_dragStartPoint; bool m_subCompEditMode = false; + bool m_isDragging = false; inline static int HORIZONTAL_LAYOUT_WIDTH_LIMIT = 600; };