Skip to content

Commit

Permalink
SplitterHandle: Consider scrollbar width
Browse files Browse the repository at this point in the history
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 ros-visualization#1545.
  • Loading branch information
rhaschke authored and AndreasR30 committed Jun 7, 2021
1 parent 9296c1f commit e18f769
Showing 1 changed file with 8 additions and 8 deletions.
16 changes: 8 additions & 8 deletions src/rviz/properties/splitter_handle.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
#include <QPaintEvent>
#include <QPainter>
#include <QTreeView>
#include <QHeaderView>

#include <rviz/properties/splitter_handle.h>

Expand All @@ -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();
}
Expand All @@ -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());
Expand Down

0 comments on commit e18f769

Please sign in to comment.