From 8c4758cc7a2d678a04f5ce9bf7f49280bc8e6f85 Mon Sep 17 00:00:00 2001 From: Mark Liversedge Date: Sun, 12 Apr 2020 22:57:34 +0100 Subject: [PATCH] ChartBar drag fixup for Qt5.10 regression .. When the widget in QScrollArea resizes the position is set to origin, which is a regression introduced sometime after Qt5.9. .. If the chart bar was scrolled then dragging a tab would cause the buttonbar to be resized temporarily as the item is removed from one index and placed at another. .. To get around this we make the buttonbar fixedWidth, which means no resize events or processing occurs. But it means we need to adjust as widgets are added and removed. .. Fortunately an existing function 'tidy()' is available to do this for us, but needed to be controlled (only resize when widgets are added or removed). .. If the regression is fixed this commit can be reverted, but it should be harmless with/without any Qt fix. --- src/Charts/ChartBar.cpp | 30 ++++++++++++++++++------------ src/Charts/ChartBar.h | 2 +- 2 files changed, 19 insertions(+), 13 deletions(-) diff --git a/src/Charts/ChartBar.cpp b/src/Charts/ChartBar.cpp index 4caa3c0d0..6b183f186 100644 --- a/src/Charts/ChartBar.cpp +++ b/src/Charts/ChartBar.cpp @@ -57,8 +57,8 @@ ChartBar::ChartBar(Context *context) : QWidget(context->mainWindow), context(con // scrollarea scrollArea = new QScrollArea(this); - scrollArea->setAutoFillBackground(false); - scrollArea->setWidgetResizable(true); + scrollArea->setAutoFillBackground(true); + scrollArea->setWidgetResizable(false); scrollArea->setFrameStyle(QFrame::NoFrame); scrollArea->setContentsMargins(0,0,0,0); scrollArea->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff); @@ -149,6 +149,9 @@ ChartBar::configChanged(qint32) scrollArea->setFixedHeight(height); buttonBar->setFixedHeight(height); + QColor col=GColor(CCHROME); + scrollArea->setStyleSheet(QString("QScrollArea { background: rgb(%1,%2,%3); }").arg(col.red()).arg(col.green()).arg(col.blue())); + foreach(ChartBarItem *b, buttons) { int width = fs.width(b->text) + (30 * dpiXFactor); if (width < (80*dpiXFactor)) width=80*dpiXFactor; @@ -184,7 +187,7 @@ ChartBar::addWidget(QString title) newbutton->installEventFilter(this); // tidy up scrollers etc - tidy(); + tidy(true); } void @@ -209,20 +212,22 @@ ChartBar::setText(int index, QString text) buttons[index]->setWidth(width < (80*dpiXFactor) ? (80*dpiXFactor) : width); buttons[index]->update(); - tidy(); // still fit ? + tidy(true); // still fit ? } // tidy up the scrollers on first show... void -ChartBar::tidy() +ChartBar::tidy(bool setwidth) { // resize to button widths + 2px spacing - int width = 2*dpiXFactor; - foreach (ChartBarItem *button, buttons) { - width += button->geometry().width() + (2*dpiXFactor); + if (setwidth) { + int width = 2*dpiXFactor; + foreach (ChartBarItem *button, buttons) { + width += button->geometry().width() + (2*dpiXFactor); + } + buttonBar->setFixedWidth(width); } - buttonBar->setMinimumWidth(width); if (buttonBar->width() > scrollArea->width()) { left->show(); right->show(); @@ -239,18 +244,18 @@ ChartBar::eventFilter(QObject *object, QEvent *e) // we do NOT move the position, we just show/hide // the left and right scrollers - tidy(); + tidy(false); } // showing us - tidy up if (object == this && e->type() == QEvent::Show) { - tidy(); + tidy(false); } // enter/leave we can track approximate mouse position and decide // if we want to 'autoscroll' if (e->type() == QEvent::Leave || e->type() == QEvent::Enter) { - tidy(); // tidy up anyway + tidy(false); // tidy up anyway } return false; @@ -319,6 +324,7 @@ ChartBar::removeWidget(int index) for (int i=0; isetMapping(buttons[i], i); + tidy(true); } void diff --git a/src/Charts/ChartBar.h b/src/Charts/ChartBar.h index ff12d7c5a..eefe1d3c4 100644 --- a/src/Charts/ChartBar.h +++ b/src/Charts/ChartBar.h @@ -58,7 +58,7 @@ public slots: void setCurrentIndex(int index); void scrollLeft(); void scrollRight(); - void tidy(); + void tidy(bool setwidth); void setChartMenu(); void menuPopup(); void configChanged(qint32); // appearance