From e18f769bd286d5c225c7e03d30571709f63d4a4b Mon Sep 17 00:00:00 2001 From: Robert Haschke Date: Sun, 18 Oct 2020 23:16:58 +0200 Subject: [PATCH] SplitterHandle: Consider scrollbar width If there is a scrollbar visible, the visible width of the viewport is reduced, which should be considered when computing the width of the second column. Without this, the viewport will scroll horizontally to bring the 2nd column into view, thus hiding the unfold arrows in the first column. Fixes #1545. --- src/rviz/properties/splitter_handle.cpp | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/src/rviz/properties/splitter_handle.cpp b/src/rviz/properties/splitter_handle.cpp index 3c2ec46a50..c385f6222c 100644 --- a/src/rviz/properties/splitter_handle.cpp +++ b/src/rviz/properties/splitter_handle.cpp @@ -32,6 +32,7 @@ #include #include #include +#include #include @@ -42,12 +43,14 @@ SplitterHandle::SplitterHandle(QTreeView* parent) { setCursor(Qt::SplitHCursor); updateGeometry(); + parent_->header()->setStretchLastSection(false); parent_->installEventFilter(this); } bool SplitterHandle::eventFilter(QObject* event_target, QEvent* event) { - if (event_target == parent_ && (event->type() == QEvent::Resize || event->type() == QEvent::Paint)) + if (event_target == parent_ && + (event->type() == QEvent::Resize || event->type() == QEvent::LayoutRequest)) { updateGeometry(); } @@ -57,13 +60,10 @@ bool SplitterHandle::eventFilter(QObject* event_target, QEvent* event) void SplitterHandle::updateGeometry() { int w = 7; - int content_width = parent_->contentsRect().width(); - int new_column_width = int(first_column_size_ratio_ * content_width); - if (new_column_width != parent_->columnWidth(0)) - { - parent_->setColumnWidth(0, new_column_width); - parent_->setColumnWidth(1, content_width - new_column_width); - } + int new_column_width = int(first_column_size_ratio_ * parent_->contentsRect().width()); + parent_->setColumnWidth(0, new_column_width); + parent_->setColumnWidth(1, parent_->viewport()->contentsRect().width() - new_column_width); + int new_x = new_column_width - w / 2 + parent_->columnViewportPosition(0); if (new_x != x() || parent_->height() != height()) setGeometry(new_x, 0, w, parent_->height());