From 916427a612a93b07d5f1beab58b326f9d0c70b70 Mon Sep 17 00:00:00 2001 From: nerix Date: Sun, 1 Oct 2023 07:13:37 +0200 Subject: [PATCH] Fix flickering when running with Direct2D (#4851) --- CHANGELOG.md | 1 + src/widgets/Notebook.cpp | 1 - src/widgets/helper/Button.cpp | 4 ++++ src/widgets/helper/Button.hpp | 8 +++++++- src/widgets/helper/NotebookButton.cpp | 2 +- src/widgets/helper/TitlebarButton.cpp | 3 +-- 6 files changed, 14 insertions(+), 5 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 4143892a..e6261d62 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -26,6 +26,7 @@ - Dev: Add `WindowManager::getLastSelectedWindow()` to replace `getMainWindow()`. (#4816) - Dev: Clarify signal connection lifetimes where applicable. (#4818) - Dev: Laid the groundwork for advanced input completion strategies. (#4639, #4846) +- Dev: Fixed flickering when running with Direct2D on Windows. (#4851) ## 2.4.5 diff --git a/src/widgets/Notebook.cpp b/src/widgets/Notebook.cpp index 3ff3648a..f9f46b76 100644 --- a/src/widgets/Notebook.cpp +++ b/src/widgets/Notebook.cpp @@ -1117,7 +1117,6 @@ void Notebook::setTabLocation(NotebookTabLocation location) void Notebook::paintEvent(QPaintEvent *event) { - BaseWidget::paintEvent(event); auto scale = this->scale(); QPainter painter(this); diff --git a/src/widgets/helper/Button.cpp b/src/widgets/helper/Button.cpp index dce0153f..b4caa299 100644 --- a/src/widgets/helper/Button.cpp +++ b/src/widgets/helper/Button.cpp @@ -133,7 +133,11 @@ void Button::setMenu(std::unique_ptr menu) void Button::paintEvent(QPaintEvent *) { QPainter painter(this); + this->paintButton(painter); +} +void Button::paintButton(QPainter &painter) +{ painter.setRenderHint(QPainter::SmoothPixmapTransform); if (!this->pixmap_.isNull()) diff --git a/src/widgets/helper/Button.hpp b/src/widgets/helper/Button.hpp index cac8c532..1bc763a9 100644 --- a/src/widgets/helper/Button.hpp +++ b/src/widgets/helper/Button.hpp @@ -56,7 +56,13 @@ signals: void leftMousePress(); protected: - virtual void paintEvent(QPaintEvent *) override; + void paintEvent(QPaintEvent * /*event*/) override; + + /// Paint this button. + /// This is intended for child classes that may want to paint the overlay. + /// This function should be used after rendering the custom button, + /// because the painter's state will be modified by this function. + void paintButton(QPainter &painter); #if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0) void enterEvent(QEnterEvent * /*event*/) override; #else diff --git a/src/widgets/helper/NotebookButton.cpp b/src/widgets/helper/NotebookButton.cpp index b7e8315a..510233d1 100644 --- a/src/widgets/helper/NotebookButton.cpp +++ b/src/widgets/helper/NotebookButton.cpp @@ -138,7 +138,7 @@ void NotebookButton::paintEvent(QPaintEvent *event) default:; } - Button::paintEvent(event); + this->paintButton(painter); } void NotebookButton::mouseReleaseEvent(QMouseEvent *event) diff --git a/src/widgets/helper/TitlebarButton.cpp b/src/widgets/helper/TitlebarButton.cpp index b4d85939..fa2d6bb2 100644 --- a/src/widgets/helper/TitlebarButton.cpp +++ b/src/widgets/helper/TitlebarButton.cpp @@ -121,8 +121,7 @@ void TitleBarButton::paintEvent(QPaintEvent *event) default:; } - Button::paintEvent(event); - // this->fancyPaint(painter); + this->paintButton(painter); } } // namespace chatterino