Preserve interactive stretch when navigating across tabs

This commit is contained in:
Trevor SANDY 2022-09-08 08:45:17 +02:00
parent aedfa16e42
commit e71ed90b3d
2 changed files with 14 additions and 5 deletions

View file

@ -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)));
@ -60,7 +60,14 @@ void lcQTreeWidgetColumnStretcher::sectionResized(int LogicalIndex, int OldSize,
Q_UNUSED(OldSize)
if (LogicalIndex == m_columnToStretch)
{
QHeaderView* HeaderView = qobject_cast<QHeaderView*>(parent());
if (HeaderView->isVisible())
m_interactiveResize = true;
m_stretchWidth = NewSize;
}
}
bool lcQTreeWidgetColumnStretcher::eventFilter(QObject* Object, QEvent* Event)
@ -79,6 +86,7 @@ bool lcQTreeWidgetColumnStretcher::eventFilter(QObject* Object, QEvent* Event)
}
else if (Event->type() == QEvent::Hide)
{
if (!m_interactiveResize)
for (int i = 0; i < HeaderView->count(); ++i)
HeaderView->setSectionResizeMode(i, i == m_columnToStretch ? QHeaderView::Stretch : QHeaderView::ResizeToContents);
}

View file

@ -20,6 +20,7 @@ private slots:
private:
const int m_columnToStretch;
bool m_interactiveResize;
int m_stretchWidth;
};