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);
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())));
}

View File

@ -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;
};

View File

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

View File

@ -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