From d1535e7827f97bf11eb063bde22113fdac802fd2 Mon Sep 17 00:00:00 2001 From: Kacper Donat Date: Mon, 10 Jun 2024 16:36:20 +0200 Subject: [PATCH] Gui: Disable changing workbench on tab bar scroll Fixes: #14164 --- src/Gui/WorkbenchSelector.cpp | 2 ++ src/Gui/WorkbenchSelector.h | 20 +++++++++++++++++++- 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/src/Gui/WorkbenchSelector.cpp b/src/Gui/WorkbenchSelector.cpp index 4d8ca65dd3..c2ded0ec6b 100644 --- a/src/Gui/WorkbenchSelector.cpp +++ b/src/Gui/WorkbenchSelector.cpp @@ -428,3 +428,5 @@ void WorkbenchTabWidget::adjustSize() parentWidget()->adjustSize(); } + +#include "moc_WorkbenchSelector.cpp" diff --git a/src/Gui/WorkbenchSelector.h b/src/Gui/WorkbenchSelector.h index 272a8b8a2a..2ae36cfd5b 100644 --- a/src/Gui/WorkbenchSelector.h +++ b/src/Gui/WorkbenchSelector.h @@ -29,6 +29,8 @@ #include #include #include +#include + #include #include #include @@ -101,7 +103,23 @@ class GuiExport WorkbenchTabWidget : public QWidget return size; } + void wheelEvent(QWheelEvent* wheelEvent) override + { + // Qt does not expose any way to programmatically control scroll of QTabBar hence + // we need to use a bit hacky solution of simulating clicks on the scroll buttons + + auto left = findChild(QString::fromUtf8("ScrollLeftButton")); + auto right = findChild(QString::fromUtf8("ScrollRightButton")); + + if (wheelEvent->angleDelta().y() > 0) { + right->click(); + } else { + left->click(); + } + } + WorkbenchItemStyle itemStyle() const { return _itemStyle; } + void setItemStyle(WorkbenchItemStyle itemStyle) { _itemStyle = itemStyle; setProperty("style", QString::fromUtf8(workbenchItemStyleToString(itemStyle))); @@ -122,7 +140,7 @@ class GuiExport WorkbenchTabWidget : public QWidget public: explicit WorkbenchTabWidget(WorkbenchGroup* aGroup, QWidget* parent = nullptr); - + void setToolBarArea(Gui::ToolBarArea area); void buildPrefMenu();