From e71ed90b3de1d01d3a42295dcd48bb8e7d213fd1 Mon Sep 17 00:00:00 2001 From: Trevor SANDY Date: Thu, 8 Sep 2022 08:45:17 +0200 Subject: [PATCH] Preserve interactive stretch when navigating across tabs --- qt/lc_qutils.cpp | 18 +++++++++++++----- qt/lc_qutils.h | 1 + 2 files changed, 14 insertions(+), 5 deletions(-) diff --git a/qt/lc_qutils.cpp b/qt/lc_qutils.cpp index f843353d..a8522960 100644 --- a/qt/lc_qutils.cpp +++ b/qt/lc_qutils.cpp @@ -47,7 +47,7 @@ float lcParseValueLocalized(const QString& Value) // Resize all columns to content except for one stretching column. (taken from QT creator) lcQTreeWidgetColumnStretcher::lcQTreeWidgetColumnStretcher(QTreeWidget *treeWidget, int columnToStretch) - : QObject(treeWidget->header()), m_columnToStretch(columnToStretch), m_stretchWidth(0) + : QObject(treeWidget->header()), m_columnToStretch(columnToStretch), m_interactiveResize(false), m_stretchWidth(0) { parent()->installEventFilter(this); connect(treeWidget->header(), SIGNAL(sectionResized(int, int, int)), SLOT(sectionResized(int, int, int))); @@ -59,8 +59,15 @@ void lcQTreeWidgetColumnStretcher::sectionResized(int LogicalIndex, int OldSize, { Q_UNUSED(OldSize) - if (LogicalIndex == m_columnToStretch) - m_stretchWidth = NewSize; + if (LogicalIndex == m_columnToStretch) + { + QHeaderView* HeaderView = qobject_cast(parent()); + + if (HeaderView->isVisible()) + m_interactiveResize = true; + + m_stretchWidth = NewSize; + } } bool lcQTreeWidgetColumnStretcher::eventFilter(QObject* Object, QEvent* Event) @@ -79,8 +86,9 @@ bool lcQTreeWidgetColumnStretcher::eventFilter(QObject* Object, QEvent* Event) } else if (Event->type() == QEvent::Hide) { - for (int i = 0; i < HeaderView->count(); ++i) - HeaderView->setSectionResizeMode(i, i == m_columnToStretch ? QHeaderView::Stretch : QHeaderView::ResizeToContents); + if (!m_interactiveResize) + for (int i = 0; i < HeaderView->count(); ++i) + HeaderView->setSectionResizeMode(i, i == m_columnToStretch ? QHeaderView::Stretch : QHeaderView::ResizeToContents); } else if (Event->type() == QEvent::Resize) { diff --git a/qt/lc_qutils.h b/qt/lc_qutils.h index f0bfecfe..5a6591ee 100644 --- a/qt/lc_qutils.h +++ b/qt/lc_qutils.h @@ -20,6 +20,7 @@ private slots: private: const int m_columnToStretch; + bool m_interactiveResize; int m_stretchWidth; };