From 2ca4b28457d7d0ef5806eb6ee2bb6a7a8d9ba8e1 Mon Sep 17 00:00:00 2001 From: Nerixyz Date: Sun, 19 Jul 2026 13:00:12 +0200 Subject: [PATCH] fix: Update pined message height if viewport resized (#7114) If the split is not 100dp wide, the calculated message height can be wrong. If the split is larger than 100dp and the message would wrap at that size, the widget would be too tall. And vice versa for splits smaller than 100dp. We do calculate the height in our resize event, but we use the size of our children. Their resize events are delivered after we're resized. So we check if we need to resize after we show the widget. This does result in a small flash where the content is sized incorrectly, but better than it being incorrect the entire time. Parent-pr: 7014 Reviewed-by: pajlada --- src/widgets/splits/PinnedMessageWidget.cpp | 16 ++++++++++++++-- src/widgets/splits/PinnedMessageWidget.hpp | 8 ++++++++ 2 files changed, 22 insertions(+), 2 deletions(-) diff --git a/src/widgets/splits/PinnedMessageWidget.cpp b/src/widgets/splits/PinnedMessageWidget.cpp index 4255884f3..cb7549408 100644 --- a/src/widgets/splits/PinnedMessageWidget.cpp +++ b/src/widgets/splits/PinnedMessageWidget.cpp @@ -319,6 +319,7 @@ void PinnedMessageWidget::refresh() this->menuButton_->setVisible(isMod); this->show(); + this->updateMessageHeightIfNeeded(); this->autoHideTimer_->stop(); if (!getSettings()->alwaysShowPinnedMessage && !this->userToggled_) @@ -340,6 +341,7 @@ void PinnedMessageWidget::toggleUserPinned() this->userToggled_ = true; this->autoHideTimer_->stop(); this->show(); + this->updateMessageHeightIfNeeded(); } } @@ -351,8 +353,9 @@ void PinnedMessageWidget::updateMessageHeight() } // Wrapped height of the label at the current viewport width. - const int width = this->messageScrollArea_->viewport()->width(); - int contentH = this->messageLabel_->heightForWidth(width); + this->lastViewportWidth_ = this->messageScrollArea_->viewport()->width(); + int contentH = + this->messageLabel_->heightForWidth(this->lastViewportWidth_); if (contentH <= 0) { contentH = this->messageLabel_->sizeHint().height(); @@ -363,6 +366,15 @@ void PinnedMessageWidget::updateMessageHeight() qBound(1, contentH, this->messageMaxHeight_)); } +void PinnedMessageWidget::updateMessageHeightIfNeeded() +{ + if (this->lastViewportWidth_ != + this->messageScrollArea_->viewport()->width()) + { + this->updateMessageHeight(); + } +} + void PinnedMessageWidget::resizeEvent(QResizeEvent *event) { BaseWidget::resizeEvent(event); diff --git a/src/widgets/splits/PinnedMessageWidget.hpp b/src/widgets/splits/PinnedMessageWidget.hpp index 97ea8c7be..128f7abe7 100644 --- a/src/widgets/splits/PinnedMessageWidget.hpp +++ b/src/widgets/splits/PinnedMessageWidget.hpp @@ -58,6 +58,12 @@ private: /// (scaled) maximum height. A vertical scrollbar appears past the cap. void updateMessageHeight(); + /// If the scroll viewport width has changed since the last time + /// updateMessageHeight() was called, update the height again, because + /// resize events for children are delivered after resize events for + /// ourselves when showing the widget. + void updateMessageHeightIfNeeded(); + TwitchChannel *channel_ = nullptr; pajlada::Signals::SignalHolder signalHolder_; @@ -80,6 +86,8 @@ private: bool userToggled_ = false; /// Invalid when no end time. QDateTime pinEndsAt_; + + int lastViewportWidth_ = -1; }; } // namespace chatterino