Minor improvements to the Win32Demo project.

Signed-off-by: Yuhang Zhao <2546789017@qq.com>
This commit is contained in:
Yuhang Zhao 2020-10-20 09:55:20 +08:00
parent 886f31d0c0
commit 17b35173ef
4 changed files with 48 additions and 16 deletions

View File

@ -313,12 +313,9 @@ bool Widget::eventFilter(QObject *object, QEvent *event)
WinNativeEventFilter::addFramelessWindow(this); WinNativeEventFilter::addFramelessWindow(this);
break; break;
case QEvent::WindowActivate: case QEvent::WindowActivate:
case QEvent::WindowDeactivate: { case QEvent::WindowDeactivate:
if (shouldDrawThemedBorder(true)) {
updateTitleBar(); updateTitleBar();
}
break; break;
}
default: default:
break; break;
} }
@ -402,16 +399,28 @@ void Widget::updateTitleBar()
ui->maximizeButton->setIcon(QIcon(QLatin1String(":/images/button_maximize_black.svg"))); ui->maximizeButton->setIcon(QIcon(QLatin1String(":/images/button_maximize_black.svg")));
} }
} }
const QColor color = m_bExtendToTitleBar ? Qt::transparent const QColor titleBarColor = m_bExtendToTitleBar ? Qt::transparent
: (themedTitleBar ? m_cThemeColor : Qt::white); : (themedTitleBar ? m_cThemeColor : Qt::white);
const QColor titleTextColor = isActiveWindow()
? ((!themedTitleBar || m_bExtendToTitleBar) ? Qt::black
: Qt::white)
: QColor("#999999");
ui->titleBarWidget->setStyleSheet(systemButtonsStyleSheet ui->titleBarWidget->setStyleSheet(systemButtonsStyleSheet
+ QLatin1String(R"( + QLatin1String(R"(
#titleLabel {
color: rgb(%1, %2, %3);
}
)")
.arg(QString::number(titleTextColor.red()),
QString::number(titleTextColor.green()),
QString::number(titleTextColor.blue()))
+ QLatin1String(R"(
#titleBarWidget { #titleBarWidget {
background-color: rgba(%1, %2, %3, %4); background-color: rgba(%1, %2, %3, %4);
} }
)") )")
.arg(QString::number(color.red()), .arg(QString::number(titleBarColor.red()),
QString::number(color.green()), QString::number(titleBarColor.green()),
QString::number(color.blue()), QString::number(titleBarColor.blue()),
QString::number(color.alpha()))); QString::number(titleBarColor.alpha())));
} }

View File

@ -65,7 +65,7 @@ private:
private: private:
Ui::Widget *ui = nullptr; Ui::Widget *ui = nullptr;
bool m_bIsWin10OrGreater = false, m_bExtendToTitleBar = false; bool m_bIsWin10OrGreater = false, m_bExtendToTitleBar = false;
const QColor m_cDefaultActiveBorderColor = /*{"707070"}*/ Qt::darkGray; const QColor m_cDefaultActiveBorderColor = {"#707070"} /*Qt::darkGray*/;
const QColor m_cDefaultInactiveBorderColor = /*{"aaaaaa"}*/ Qt::gray; const QColor m_cDefaultInactiveBorderColor = {"#aaaaaa"} /*Qt::gray*/;
QColor m_cThemeColor = Qt::white; QColor m_cThemeColor = Qt::white;
}; };

View File

@ -50,6 +50,22 @@
<property name="bottomMargin"> <property name="bottomMargin">
<number>0</number> <number>0</number>
</property> </property>
<item>
<spacer name="horizontalSpacer_7">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeType">
<enum>QSizePolicy::Fixed</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>3</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item> <item>
<widget class="QPushButton" name="iconButton"> <widget class="QPushButton" name="iconButton">
<property name="text"> <property name="text">
@ -62,9 +78,12 @@
<property name="orientation"> <property name="orientation">
<enum>Qt::Horizontal</enum> <enum>Qt::Horizontal</enum>
</property> </property>
<property name="sizeType">
<enum>QSizePolicy::Fixed</enum>
</property>
<property name="sizeHint" stdset="0"> <property name="sizeHint" stdset="0">
<size> <size>
<width>40</width> <width>3</width>
<height>20</height> <height>20</height>
</size> </size>
</property> </property>

View File

@ -998,7 +998,6 @@ void UpdateFrameMarginsForWindow(const HWND handle)
} }
} else { } else {
margins.cyTopHeight = 1; margins.cyTopHeight = 1;
//margins.cyTopHeight = GetFrameSizeForWindow(handle, TRUE).top;
} }
if (shouldUseNativeTitleBar()) { if (shouldUseNativeTitleBar()) {
// If we are going to use the native title bar, // If we are going to use the native title bar,
@ -1625,12 +1624,17 @@ bool WinNativeEventFilter::nativeEventFilter(const QByteArray &eventType,
if (shouldHaveWindowFrame()) { if (shouldHaveWindowFrame()) {
*result = 0; *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)) { if (!shouldHaveWindowFrame() && !IsFullScreen(msg->hwnd) && !IsMaximized(msg->hwnd)) {
// Fix the flickering problem when resizing. // Fix the flickering problem when resizing.
// Don't modify the left, right or bottom edge because // Don't modify the left, right or bottom edge because
// a border line will be seen (at least on Win10). // a border line will be seen (at least on Win10).
//clientRect->top -= 1; clientRect->top -= 1;
} }
*/
return true; return true;
} }
// These undocumented messages are sent to draw themed window // These undocumented messages are sent to draw themed window