Fix two issues.

1. The border line may disappear when resizing: fixed by change the line width to 2px.
2. Some part of the window become totally transparent after DPI changes: fixed by calling update() after DPI changes.

Signed-off-by: Yuhang Zhao <2546789017@qq.com>
This commit is contained in:
Yuhang Zhao 2020-10-19 22:07:12 +08:00
parent 47910161c9
commit 886f31d0c0
1 changed files with 10 additions and 1 deletions

View File

@ -32,6 +32,11 @@
#include <QSettings>
#include <qt_windows.h>
// Some old SDK doesn't have this value.
#ifndef WM_DPICHANGED
#define WM_DPICHANGED 0x02E0
#endif
// Copied from windowsx.h
#define GET_X_LPARAM(lp) ((int) (short) LOWORD(lp))
#define GET_Y_LPARAM(lp) ((int) (short) HIWORD(lp))
@ -289,6 +294,7 @@ bool Widget::eventFilter(QObject *object, QEvent *event)
{
Q_ASSERT(object);
Q_ASSERT(event);
Q_ASSERT(object == this);
switch (event->type()) {
case QEvent::WindowStateChange: {
if (shouldDrawBorder(true)) {
@ -349,6 +355,9 @@ bool Widget::nativeEvent(const QByteArray &eventType, void *message, long *resul
}
break;
}
case WM_DPICHANGED:
update();
break;
default:
break;
}
@ -362,7 +371,7 @@ void Widget::paintEvent(QPaintEvent *event)
if (shouldDrawBorder()) {
QPainter painter(this);
painter.save();
painter.setPen(borderColor());
painter.setPen({borderColor(), 2.0});
painter.drawLine(0, 0, width(), 0);
painter.drawLine(0, height(), width(), height());
painter.drawLine(0, 0, 0, height());