diff --git a/plugins/channelrx/demoddab/dabcarrierplot.cpp b/plugins/channelrx/demoddab/dabcarrierplot.cpp index c1f2b620c..385778fad 100644 --- a/plugins/channelrx/demoddab/dabcarrierplot.cpp +++ b/plugins/channelrx/demoddab/dabcarrierplot.cpp @@ -31,6 +31,7 @@ DABCarrierPlot::DABCarrierPlot(QWidget *parent) : { setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed); setMinimumHeight(110); + setAttribute(Qt::WA_OpaquePaintEvent, true); setToolTip(tr("Carrier to noise ratio of each carrier, from the null symbol.\n" "Notches are multipath; dips over a few carriers are interference.\n" "The dashed line is the median (the C/N statistic).")); diff --git a/sdrgui/dtv/dtvscope.cpp b/sdrgui/dtv/dtvscope.cpp index 2bca02064..a9f2bcd11 100644 --- a/sdrgui/dtv/dtvscope.cpp +++ b/sdrgui/dtv/dtvscope.cpp @@ -50,6 +50,7 @@ DTVScope::DTVScope(QWidget *parent) : m_lastRowTime(0) { setMinimumSize(300, 150); + setAttribute(Qt::WA_OpaquePaintEvent, true); setView(Response); } diff --git a/sdrgui/gui/rollupcontents.cpp b/sdrgui/gui/rollupcontents.cpp index 008811e03..007be4a95 100644 --- a/sdrgui/gui/rollupcontents.cpp +++ b/sdrgui/gui/rollupcontents.cpp @@ -33,8 +33,9 @@ RollupContents::RollupContents(QWidget* parent) : QWidget(parent), m_streamIndicator("S"), // m_channelWidget(true), - m_newHeight(0), - m_transparentBackground(false) + m_transparentBackground(false), + m_arranging(false), + m_arrangePending(false) { setMinimumSize(250, 150); setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::MinimumExpanding); @@ -98,7 +99,7 @@ bool RollupContents::hasExpandableWidgets() { QWidget* r = qobject_cast(children()[i]); - if (r && isRollupChild(r) && !r->isHidden() && (r->sizePolicy().verticalPolicy() == QSizePolicy::Expanding)) { + if (r && isRollupChild(r) && !r->isHidden() && isExpandingChild(r)) { return true; } } @@ -106,6 +107,36 @@ bool RollupContents::hasExpandableWidgets() return false; } int RollupContents::arrangeRollups() +{ + // Resizing a child, or setting our own minimum height, can have Qt deliver a resize + // event synchronously, which comes straight back here. Running that nested would + // reposition the children from the inner call and then finish the outer one with a + // stale cursor. Note it instead and repeat the arrangement, so the sizes the nested + // call was reacting to are still taken into account + if (m_arranging) + { + m_arrangePending = true; + return m_minimumSizeHint.height(); + } + + m_arranging = true; + + int pos = 0; + int passes = 0; + + do + { + m_arrangePending = false; + pos = arrangeRollupsOnce(); + } + while (m_arrangePending && (++passes < 4)); + + m_arranging = false; + + return pos; +} + +int RollupContents::arrangeRollupsOnce() { QFontMetrics fm(font()); int pos; @@ -124,7 +155,7 @@ int RollupContents::arrangeRollups() pos += fm.height() + 2; if (!r->isHidden()) { - if (r->sizePolicy().verticalPolicy() & QSizePolicy::ExpandFlag) { + if (isExpandingChild(r)) { expandingChildren++; } int h = 0; @@ -169,9 +200,13 @@ int RollupContents::arrangeRollups() // In the future, we should probably respect 'Vertical Stretch' int extraSpace; int firstExtra; - if ((expandingChildren > 0) && (m_newHeight > pos)) + // height() rather than a value cached in resizeEvent: arrangeRollups() is called + // from layout requests, from children being shown or hidden and from clicks on the + // section headers, and in all of those the cached value is whatever the last resize + // happened to be - or zero before the first one + if ((expandingChildren > 0) && (height() > pos)) { - int totalExtra = m_newHeight - pos; + int totalExtra = height() - pos; extraSpace = totalExtra / expandingChildren; firstExtra = totalExtra - (extraSpace * expandingChildren); } @@ -199,7 +234,7 @@ int RollupContents::arrangeRollups() } else { h = r->minimumSizeHint().height(); } - if (r->sizePolicy().verticalPolicy() & QSizePolicy::ExpandFlag) + if (isExpandingChild(r)) { h += extraSpace; h += firstExtra; @@ -373,7 +408,6 @@ int RollupContents::paintRollup(QWidget* rollup, int pos, QPainter* p, bool last void RollupContents::resizeEvent(QResizeEvent* size) { - m_newHeight = size->size().height(); arrangeRollups(); QWidget::resizeEvent(size); } @@ -472,3 +506,8 @@ bool RollupContents::isRollupChild(QWidget *childWidget) { return (qobject_cast(childWidget) == nullptr); // exclude Dialogs from rollups } + +bool RollupContents::isExpandingChild(const QWidget *childWidget) +{ + return (childWidget->sizePolicy().verticalPolicy() & QSizePolicy::ExpandFlag) != 0; +} diff --git a/sdrgui/gui/rollupcontents.h b/sdrgui/gui/rollupcontents.h index dec704889..8c364eaf5 100644 --- a/sdrgui/gui/rollupcontents.h +++ b/sdrgui/gui/rollupcontents.h @@ -62,10 +62,20 @@ protected: private: static bool isRollupChild(QWidget *childWidget); //!< chidl is part of rollups (ex: not a dialog) + //!< Whether a child takes a share of any space left over. MinimumExpanding carries + //!< ExpandFlag as well as Expanding, and hasExpandableWidgets() and arrangeRollups() + //!< have to agree, or the window is made fixed size while its contents expand + static bool isExpandingChild(const QWidget *childWidget); + int arrangeRollupsOnce(); // bool m_channelWidget; - int m_newHeight; QSize m_minimumSizeHint; bool m_transparentBackground; + //!< arrangeRollups() resizes children and sets our own minimum height, either of + //!< which can have Qt deliver a resize event synchronously and call us again while + //!< we are part way through positioning + bool m_arranging; + //!< Set when that happens, so the arrangement is repeated rather than lost + bool m_arrangePending; }; #endif // INCLUDE_ROLLUPCONTENTS_H