diff --git a/src/ui/ControlsPanel.cpp b/src/ui/ControlsPanel.cpp index 78f8898..9cea8a2 100644 --- a/src/ui/ControlsPanel.cpp +++ b/src/ui/ControlsPanel.cpp @@ -65,6 +65,18 @@ QWidget* makeRow(ControlAction action, const ControlContext& context, QWidget* p return row; } +// Adds a freshly built widget to the rows and shows it. +// +// The show is what makes it count. A widget created under an already-visible parent +// starts hidden, and a layout treats a hidden item as empty -- it contributes nothing +// to the size hint until something shows it, which otherwise does not happen until the +// event loop next runs, long after the panel has measured itself. +void addAndShow(QVBoxLayout* layout, QWidget* widget) +{ + layout->addWidget(widget); + widget->show(); +} + } // namespace ControlsPanel::ControlsPanel(const GameWorldView* view, QWidget* parent) @@ -173,7 +185,7 @@ void ControlsPanel::rebuild(const ControlContext& context) for (ControlAction action : m_shownContextActions) { - m_rowsLayout->addWidget(makeRow(action, context, m_rows)); + addAndShow(m_rowsLayout, makeRow(action, context, m_rows)); } // The always-available block sits under a divider in every context, the General one @@ -185,17 +197,17 @@ void ControlsPanel::rebuild(const ControlContext& context) divider->setFrameShape(QFrame::HLine); divider->setFrameShadow(QFrame::Plain); m_rowsLayout->addSpacing(6); - m_rowsLayout->addWidget(divider); + addAndShow(m_rowsLayout, divider); QLabel* caption = new QLabel(tr("ALWAYS AVAILABLE"), m_rows); caption->setObjectName(QStringLiteral("controlCaption")); caption->setFont(makeSpacedFont(font(), /*bold*/ false, /*pointSizeDelta*/ -1)); - m_rowsLayout->addWidget(caption); + addAndShow(m_rowsLayout, caption); } for (ControlAction action : m_shownAlwaysActions) { - m_rowsLayout->addWidget(makeRow(action, context, m_rows)); + addAndShow(m_rowsLayout, makeRow(action, context, m_rows)); } m_rows->setVisible(!m_collapsed);