Salome HOME
bos #32216 [CEA] GUI ergonomic: fix horizontal scrollbar position.
[modules/gui.git] / src / Qtx / QtxTreeView.cxx
index b3bee2242a7aa4fececffad28737832a3d9cf5f6..17e2dfab1dc3d8e16c3031762d75caf1f0beaa81 100644 (file)
@@ -25,6 +25,7 @@
 #include <QHeaderView>
 #include <QMenu>
 #include <QMouseEvent>
+#include <QScrollBar>
 
 /*!
   \class QtxTreeView::Header
@@ -390,6 +391,21 @@ void QtxTreeView::setModel( QAbstractItemModel* m )
              this, SLOT( onAppropriate( Qt::Orientation, int, int ) ) );
 }
 
+// This method fixes problem with Object Browser horizontal scrollbar automatic scrolling to the right
+void QtxTreeView::scrollTo(const QModelIndex &index,
+                           QAbstractItemView::ScrollHint hint)
+{
+  QScrollBar* aScrollBar = horizontalScrollBar();
+  if (aScrollBar) {
+    int horPos = aScrollBar->value();
+    QTreeView::scrollTo(index, hint);
+    aScrollBar->setValue(horPos);
+  }
+  else {
+    QTreeView::scrollTo(index, hint);
+  }
+}
+
 void QtxTreeView::onAppropriate( Qt::Orientation orient, int first, int last )
 {
   if( orient==Qt::Horizontal )