diff --git a/src/widgets/widgets/qdockarealayout.cpp b/src/widgets/widgets/qdockarealayout.cpp index 0f8a4850041..33162bad3bf 100644 --- a/src/widgets/widgets/qdockarealayout.cpp +++ b/src/widgets/widgets/qdockarealayout.cpp @@ -1107,6 +1107,21 @@ static QRect dockedGeometry(QWidget *widget) return result; } +bool QDockAreaLayoutInfo::hasGapItem(const QList &path) const +{ + // empty path has no gap item + if (path.isEmpty()) + return false; + + // Index -1 isn't a gap + // Index out of range points at a position to be created. That isn't a gap either. + const int index = path.constFirst(); + if (index < 0 || index >= item_list.count()) + return false; + + return item_list[index].flags & QDockAreaLayoutItem::GapItem; +} + bool QDockAreaLayoutInfo::insertGap(const QList &path, QLayoutItem *dockWidgetItem) { Q_ASSERT(!path.isEmpty()); diff --git a/src/widgets/widgets/qdockarealayout_p.h b/src/widgets/widgets/qdockarealayout_p.h index 03e84d31446..4a5e8901504 100644 --- a/src/widgets/widgets/qdockarealayout_p.h +++ b/src/widgets/widgets/qdockarealayout_p.h @@ -135,6 +135,7 @@ public: void clear(); bool isEmpty() const; + bool hasGapItem(const QList &path) const; bool onlyHasPlaceholders() const; bool hasFixedSize() const; QList findSeparator(const QPoint &pos) const; diff --git a/src/widgets/widgets/qmainwindowlayout.cpp b/src/widgets/widgets/qmainwindowlayout.cpp index 0971ac5d581..e9cfd05007a 100644 --- a/src/widgets/widgets/qmainwindowlayout.cpp +++ b/src/widgets/widgets/qmainwindowlayout.cpp @@ -541,8 +541,12 @@ bool QDockWidgetGroupWindow::hover(QLayoutItem *widgetItem, const QPoint &mouseP auto newGapPos = newState.gapIndex(mousePos, nestingEnabled, tabMode); Q_ASSERT(!newGapPos.isEmpty()); - if (newGapPos == currentGapPos) - return false; // gap is already there + + // Do not insert a new gap item, if the current position already is a gap, + // or if the group window contains one + if (newGapPos == currentGapPos || newState.hasGapItem(newGapPos)) + return false; + currentGapPos = newGapPos; newState.insertGap(currentGapPos, widgetItem); newState.fitItems();