diff --git a/src/Mod/Sketcher/Gui/TaskSketcherConstraints.cpp b/src/Mod/Sketcher/Gui/TaskSketcherConstraints.cpp
index 49ac068091..ac63cf052d 100644
--- a/src/Mod/Sketcher/Gui/TaskSketcherConstraints.cpp
+++ b/src/Mod/Sketcher/Gui/TaskSketcherConstraints.cpp
@@ -1373,10 +1373,7 @@ void TaskSketcherConstraints::onSelectionChanged(const Gui::SelectionChanges& ms
auto tmpBlock = ui->listWidgetConstraints->blockSignals(true);
item->setSelected(select);
ui->listWidgetConstraints->blockSignals(tmpBlock);
- if (select && ui->listWidgetConstraints->model()) { // scrollTo only on select, not de-select
- QModelIndex index = ui->listWidgetConstraints->model()->index(i, 0);
- ui->listWidgetConstraints->scrollTo(index, QAbstractItemView::PositionAtCenter);
- }
+ SketcherGui::scrollTo(ui->listWidgetConstraints, i, select);
break;
}
}
diff --git a/src/Mod/Sketcher/Gui/TaskSketcherElements.cpp b/src/Mod/Sketcher/Gui/TaskSketcherElements.cpp
index 93771c5440..95be1ebbea 100644
--- a/src/Mod/Sketcher/Gui/TaskSketcherElements.cpp
+++ b/src/Mod/Sketcher/Gui/TaskSketcherElements.cpp
@@ -1435,6 +1435,7 @@ void TaskSketcherElements::onSelectionChanged(const Gui::SelectionChanges& msg)
if (item->ElementNbr == ElementId) {
item->isLineSelected = select;
modified_item = item;
+ SketcherGui::scrollTo(ui->listWidgetElements, i, select);
break;
}
}
diff --git a/src/Mod/Sketcher/Gui/Utils.h b/src/Mod/Sketcher/Gui/Utils.h
index e5b38ecaa3..3bbfbe0618 100644
--- a/src/Mod/Sketcher/Gui/Utils.h
+++ b/src/Mod/Sketcher/Gui/Utils.h
@@ -27,6 +27,7 @@
#include
#include
#include
+#include
#include "AutoConstraint.h"
#include "ViewProviderSketchGeometryExtension.h"
@@ -210,6 +211,14 @@ bool areCollinear(const Base::Vector2d& p1, const Base::Vector2d& p2, const Base
int indexOfGeoId(const std::vector& vec, int elem);
+inline void scrollTo(QListWidget* list, int i, bool select)
+{
+ if (select && list->model()) { // scrollTo only on select, not de-select
+ QModelIndex index = list->model()->index(i, 0);
+ list->scrollTo(index, QAbstractItemView::PositionAtCenter);
+ }
+}
+
} // namespace SketcherGui
/// converts a 2D vector into a 3D vector in the XY plane