From d2ae838a7c6a49eb826ddf8de115306d11dd4d30 Mon Sep 17 00:00:00 2001 From: Eirik Aavitsland Date: Tue, 8 Oct 2019 13:47:28 +0200 Subject: Item views: fix regression causing unexpected widget overlapping A certain geometry adjustment was (practically) introduced in Qt 5.11, and caused very surprising behavior, where item widgets will often overwrite neighbouring cells. This has resulted in a number of bug reports. Since the adjustment has such serious side effects, and does not seem to be relevant any longer for the issue for which it was intended, remove it here. More details: From early Qt 4 times, QStyledItemDelegate would do some automatic expansion of the geometry of editor widgets - but only if the layout was RightToLeft. Hence, the effect of it was rarely seen. QTBUG-37433 did, for Qt 5.10, and complained about it. However, the resulting code change did not remove the adjustment, but instead extended it to apply to the normal LeftToRight layout also. Hence, more users experienced it, and reported it as a regression. Also, now in Qt 5.13, it seems Qt has changed in other ways, and the geometry adjustment no longer seems to help (or indeed make any difference to) the original case in QTBUG-37433. Fixes: QTBUG-78495 Fixes: QTBUG-76011 Fixes: QTBUG-68476 Change-Id: I4a4e873969eb1d89843f98fc63d90371207515d1 Reviewed-by: Paul Olav Tvete --- src/widgets/itemviews/qstyleditemdelegate.cpp | 9 --------- 1 file changed, 9 deletions(-) (limited to 'src/widgets') diff --git a/src/widgets/itemviews/qstyleditemdelegate.cpp b/src/widgets/itemviews/qstyleditemdelegate.cpp index 22067851cb..702e290da3 100644 --- a/src/widgets/itemviews/qstyleditemdelegate.cpp +++ b/src/widgets/itemviews/qstyleditemdelegate.cpp @@ -514,15 +514,6 @@ void QStyledItemDelegate::updateEditorGeometry(QWidget *editor, QStyle *style = widget ? widget->style() : QApplication::style(); QRect geom = style->subElementRect(QStyle::SE_ItemViewItemText, &opt, widget); - const int delta = qSmartMinSize(editor).width() - geom.width(); - if (delta > 0) { - //we need to widen the geometry - if (editor->layoutDirection() == Qt::RightToLeft) - geom.adjust(-delta, 0, 0, 0); - else - geom.adjust(0, 0, delta, 0); - } - editor->setGeometry(geom); } -- cgit v1.2.3 From 3dbc7596a3b7aca37e80f76288d3ab761ddd247a Mon Sep 17 00:00:00 2001 From: Volker Hilsheimer Date: Tue, 8 Oct 2019 10:56:44 +0200 Subject: Drag'n'Drop: fix crash when widgets are destroyed during event handling Widgets might be destroyed when handling a dragMoveEvent, in which case the following code will operate on dangling pointers or null pointers. Use a QPointer to watch for the original event receiver to disappear, and add the necessary checks for the objects we deliver events to being null. Change-Id: I4ca2f182540ae21113f4bea4e5c569e983cc58bf Fixes: QTBUG-78907 Reviewed-by: Gatis Paeglis --- src/widgets/kernel/qwidgetwindow.cpp | 22 +++++++++++++--------- 1 file changed, 13 insertions(+), 9 deletions(-) (limited to 'src/widgets') diff --git a/src/widgets/kernel/qwidgetwindow.cpp b/src/widgets/kernel/qwidgetwindow.cpp index fbc71cd0ea..aad505ed29 100644 --- a/src/widgets/kernel/qwidgetwindow.cpp +++ b/src/widgets/kernel/qwidgetwindow.cpp @@ -885,7 +885,7 @@ void QWidgetWindow::handleDragEnterEvent(QDragEnterEvent *event, QWidget *widget void QWidgetWindow::handleDragMoveEvent(QDragMoveEvent *event) { - auto *widget = findDnDTarget(m_widget, event->pos()); + QPointer widget = findDnDTarget(m_widget, event->pos()); if (!widget) { event->ignore(); if (m_dragTarget) { // Send DragLeave to previous @@ -908,14 +908,18 @@ void QWidgetWindow::handleDragMoveEvent(QDragMoveEvent *event) QGuiApplication::forwardEvent(m_dragTarget, &leaveEvent, event); m_dragTarget = nullptr; } - // Send DragEnter to new widget. - handleDragEnterEvent(static_cast(event), widget); - // Handling 'DragEnter' should suffice for the application. - translated.setDropAction(event->dropAction()); - translated.setAccepted(event->isAccepted()); - // The drag enter event is always immediately followed by a drag move event, - // see QDragEnterEvent documentation. - QGuiApplication::forwardEvent(m_dragTarget, &translated, event); + // widget might have been deleted when handling the leaveEvent + if (widget) { + // Send DragEnter to new widget. + handleDragEnterEvent(static_cast(event), widget); + // Handling 'DragEnter' should suffice for the application. + translated.setDropAction(event->dropAction()); + translated.setAccepted(event->isAccepted()); + // The drag enter event is always immediately followed by a drag move event, + // see QDragEnterEvent documentation. + if (m_dragTarget) + QGuiApplication::forwardEvent(m_dragTarget, &translated, event); + } } event->setAccepted(translated.isAccepted()); event->setDropAction(translated.dropAction()); -- cgit v1.2.3 From 31012df705c37503be00f0ddc2c323e73fd28067 Mon Sep 17 00:00:00 2001 From: Andre de la Rocha Date: Mon, 2 Sep 2019 16:46:07 +0200 Subject: Fix QGraphicsScene::update() performance A previous fix has caused a performance degradation while adding a check for avoiding adding duplicated rectangles to the update list. This patch fixes it by using a std::set instead of a QList, avoiding duplication while using an O(log N) operation, instead of the O(N) used before. Fixes: QTBUG-77952 Change-Id: Ifa9fbf110e0bad60ee02a42d91281981fd98ceab Reviewed-by: Volker Hilsheimer --- src/widgets/graphicsview/qgraphicsscene.cpp | 13 ++++++++++--- src/widgets/graphicsview/qgraphicsscene_p.h | 17 ++++++++++++++++- 2 files changed, 26 insertions(+), 4 deletions(-) (limited to 'src/widgets') diff --git a/src/widgets/graphicsview/qgraphicsscene.cpp b/src/widgets/graphicsview/qgraphicsscene.cpp index 5238ea2f5c..03717d5d1a 100644 --- a/src/widgets/graphicsview/qgraphicsscene.cpp +++ b/src/widgets/graphicsview/qgraphicsscene.cpp @@ -386,7 +386,15 @@ void QGraphicsScenePrivate::_q_emitUpdated() // Notify the changes to anybody interested. QList oldUpdatedRects; - oldUpdatedRects = updateAll ? (QList() << q->sceneRect()) : updatedRects; + if (updateAll) { + oldUpdatedRects << q->sceneRect(); + } else { + // Switch to a ranged constructor in Qt 6... + oldUpdatedRects.reserve(int(updatedRects.size())); + std::copy(updatedRects.cbegin(), updatedRects.cend(), + std::back_inserter(oldUpdatedRects)); + } + updateAll = false; updatedRects.clear(); emit q->changed(oldUpdatedRects); @@ -3219,8 +3227,7 @@ void QGraphicsScene::update(const QRectF &rect) view->d_func()->updateRectF(rect); } } else { - if (!d->updatedRects.contains(rect)) - d->updatedRects << rect; + d->updatedRects.insert(rect); } } diff --git a/src/widgets/graphicsview/qgraphicsscene_p.h b/src/widgets/graphicsview/qgraphicsscene_p.h index a2d13436fc..14bafe6678 100644 --- a/src/widgets/graphicsview/qgraphicsscene_p.h +++ b/src/widgets/graphicsview/qgraphicsscene_p.h @@ -69,6 +69,9 @@ #include #include +#include +#include + QT_REQUIRE_CONFIG(graphicsview); QT_BEGIN_NAMESPACE @@ -122,7 +125,19 @@ public: QRectF growingItemsBoundingRect; void _q_emitUpdated(); - QList updatedRects; + + struct UpdatedRectsCmp + { + bool operator() (const QRectF &a, const QRectF &b) const noexcept + { + return std::make_tuple(a.y(), a.x(), a.height(), a.width()) + < std::make_tuple(b.y(), b.x(), b.height(), b.width()); + } + }; + + // std::set was used here instead of std::unordered_set due to requiring only a comparator and + // showing equivalent performance in empirical measurements within the ranges of interest... + std::set updatedRects; QPainterPath selectionArea; int selectionChanging; -- cgit v1.2.3 From 365f70be6ed53bf8b9ba7c5a78d5683e4ff8fe79 Mon Sep 17 00:00:00 2001 From: Nico Vertriest Date: Thu, 10 Oct 2019 14:45:21 +0200 Subject: Doc: Correct snippet about customizing QMenuBar Task-number: QTBUG-79129 Change-Id: I1f8da3b429ab8543ca1f0b7079d0f50bbeea8eb5 Reviewed-by: Paul Wicking Reviewed-by: Volker Hilsheimer --- src/widgets/doc/snippets/code/doc_src_stylesheet.qdoc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/widgets') diff --git a/src/widgets/doc/snippets/code/doc_src_stylesheet.qdoc b/src/widgets/doc/snippets/code/doc_src_stylesheet.qdoc index 098eaf4717..b0d042566f 100644 --- a/src/widgets/doc/snippets/code/doc_src_stylesheet.qdoc +++ b/src/widgets/doc/snippets/code/doc_src_stylesheet.qdoc @@ -1107,10 +1107,10 @@ QMenu::indicator:exclusive:checked:selected { QMenuBar { background-color: qlineargradient(x1:0, y1:0, x2:0, y2:1, stop:0 lightgray, stop:1 darkgray); + spacing: 3px; /* spacing between menu bar items */ } QMenuBar::item { - spacing: 3px; /* spacing between menu bar items */ padding: 1px 4px; background: transparent; border-radius: 4px; -- cgit v1.2.3