From 17b35173ef42a21d0c091956e570164c9a37677f Mon Sep 17 00:00:00 2001 From: Yuhang Zhao <2546789017@qq.com> Date: Tue, 20 Oct 2020 09:55:20 +0800 Subject: [PATCH] Minor improvements to the Win32Demo project. Signed-off-by: Yuhang Zhao <2546789017@qq.com> --- examples/Win32Demo/widget.cpp | 31 ++++++++++++++++++++----------- examples/Win32Demo/widget.h | 4 ++-- examples/Win32Demo/widget.ui | 21 ++++++++++++++++++++- winnativeeventfilter.cpp | 8 ++++++-- 4 files changed, 48 insertions(+), 16 deletions(-) diff --git a/examples/Win32Demo/widget.cpp b/examples/Win32Demo/widget.cpp index 3cd6cae..50fe086 100644 --- a/examples/Win32Demo/widget.cpp +++ b/examples/Win32Demo/widget.cpp @@ -313,12 +313,9 @@ bool Widget::eventFilter(QObject *object, QEvent *event) WinNativeEventFilter::addFramelessWindow(this); break; case QEvent::WindowActivate: - case QEvent::WindowDeactivate: { - if (shouldDrawThemedBorder(true)) { - updateTitleBar(); - } + case QEvent::WindowDeactivate: + updateTitleBar(); break; - } default: break; } @@ -402,16 +399,28 @@ void Widget::updateTitleBar() ui->maximizeButton->setIcon(QIcon(QLatin1String(":/images/button_maximize_black.svg"))); } } - const QColor color = m_bExtendToTitleBar ? Qt::transparent - : (themedTitleBar ? m_cThemeColor : Qt::white); + const QColor titleBarColor = m_bExtendToTitleBar ? Qt::transparent + : (themedTitleBar ? m_cThemeColor : Qt::white); + const QColor titleTextColor = isActiveWindow() + ? ((!themedTitleBar || m_bExtendToTitleBar) ? Qt::black + : Qt::white) + : QColor("#999999"); ui->titleBarWidget->setStyleSheet(systemButtonsStyleSheet + QLatin1String(R"( +#titleLabel { + color: rgb(%1, %2, %3); +} +)") + .arg(QString::number(titleTextColor.red()), + QString::number(titleTextColor.green()), + QString::number(titleTextColor.blue())) + + QLatin1String(R"( #titleBarWidget { background-color: rgba(%1, %2, %3, %4); } )") - .arg(QString::number(color.red()), - QString::number(color.green()), - QString::number(color.blue()), - QString::number(color.alpha()))); + .arg(QString::number(titleBarColor.red()), + QString::number(titleBarColor.green()), + QString::number(titleBarColor.blue()), + QString::number(titleBarColor.alpha()))); } diff --git a/examples/Win32Demo/widget.h b/examples/Win32Demo/widget.h index 53f21b0..ebb187a 100644 --- a/examples/Win32Demo/widget.h +++ b/examples/Win32Demo/widget.h @@ -65,7 +65,7 @@ private: private: Ui::Widget *ui = nullptr; bool m_bIsWin10OrGreater = false, m_bExtendToTitleBar = false; - const QColor m_cDefaultActiveBorderColor = /*{"707070"}*/ Qt::darkGray; - const QColor m_cDefaultInactiveBorderColor = /*{"aaaaaa"}*/ Qt::gray; + const QColor m_cDefaultActiveBorderColor = {"#707070"} /*Qt::darkGray*/; + const QColor m_cDefaultInactiveBorderColor = {"#aaaaaa"} /*Qt::gray*/; QColor m_cThemeColor = Qt::white; }; diff --git a/examples/Win32Demo/widget.ui b/examples/Win32Demo/widget.ui index 9bb08b4..d0c6b96 100644 --- a/examples/Win32Demo/widget.ui +++ b/examples/Win32Demo/widget.ui @@ -50,6 +50,22 @@ 0 + + + + Qt::Horizontal + + + QSizePolicy::Fixed + + + + 3 + 20 + + + + @@ -62,9 +78,12 @@ Qt::Horizontal + + QSizePolicy::Fixed + - 40 + 3 20 diff --git a/winnativeeventfilter.cpp b/winnativeeventfilter.cpp index 88e6388..f50c36b 100644 --- a/winnativeeventfilter.cpp +++ b/winnativeeventfilter.cpp @@ -998,7 +998,6 @@ void UpdateFrameMarginsForWindow(const HWND handle) } } else { margins.cyTopHeight = 1; - //margins.cyTopHeight = GetFrameSizeForWindow(handle, TRUE).top; } if (shouldUseNativeTitleBar()) { // If we are going to use the native title bar, @@ -1625,12 +1624,17 @@ bool WinNativeEventFilter::nativeEventFilter(const QByteArray &eventType, if (shouldHaveWindowFrame()) { *result = 0; } + /* + // It does solve the flickering issue indeed, however, it also + // causes a lot of new issues when we are trying to draw + // something on the window manually through QPainter. if (!shouldHaveWindowFrame() && !IsFullScreen(msg->hwnd) && !IsMaximized(msg->hwnd)) { // Fix the flickering problem when resizing. // Don't modify the left, right or bottom edge because // a border line will be seen (at least on Win10). - //clientRect->top -= 1; + clientRect->top -= 1; } + */ return true; } // These undocumented messages are sent to draw themed window