Minor tweaks

Signed-off-by: Yuhang Zhao <2546789017@qq.com>
This commit is contained in:
Yuhang Zhao 2021-03-04 15:45:10 +08:00
parent 310b44b8c4
commit eeba7d854f
4 changed files with 13 additions and 7 deletions

View File

@ -1,6 +1,6 @@
TARGET = Quick TARGET = Quick
TEMPLATE = app TEMPLATE = app
QT += quick QT += quick quickcontrols2
HEADERS += ../../framelessquickhelper.h HEADERS += ../../framelessquickhelper.h
SOURCES += ../../framelessquickhelper.cpp main.cpp SOURCES += ../../framelessquickhelper.cpp main.cpp
RESOURCES += qml.qrc RESOURCES += qml.qrc

View File

@ -25,6 +25,7 @@
#include "../../framelessquickhelper.h" #include "../../framelessquickhelper.h"
#include <QGuiApplication> #include <QGuiApplication>
#include <QQmlApplicationEngine> #include <QQmlApplicationEngine>
#include <QQuickStyle>
int main(int argc, char *argv[]) int main(int argc, char *argv[])
{ {
@ -52,6 +53,12 @@ int main(int argc, char *argv[])
QGuiApplication application(argc, argv); QGuiApplication application(argc, argv);
#if (QT_VERSION >= QT_VERSION_CHECK(6, 0, 0))
QQuickStyle::setStyle(QString::fromUtf8("Basic"));
#else
QQuickStyle::setStyle(QString::fromUtf8("Default"));
#endif
QQmlApplicationEngine engine; QQmlApplicationEngine engine;
qmlRegisterType<FramelessQuickHelper>("wangwenx190.Utils", 1, 0, "FramelessHelper"); qmlRegisterType<FramelessQuickHelper>("wangwenx190.Utils", 1, 0, "FramelessHelper");
const QUrl mainQmlUrl(QString::fromUtf8("qrc:///qml/main.qml")); const QUrl mainQmlUrl(QString::fromUtf8("qrc:///qml/main.qml"));

View File

@ -172,6 +172,6 @@ Window {
Component.onCompleted: { Component.onCompleted: {
framelessHelper.setWindowFrameVisible(framelessHelper.canHaveWindowFrame) framelessHelper.setWindowFrameVisible(framelessHelper.canHaveWindowFrame)
framelessHelper.removeWindowFrame(true) framelessHelper.removeWindowFrame()
} }
} }

View File

@ -780,10 +780,7 @@ void triggerFrameChange(const QWindow *window)
void updateFrameMargins(const QWindow *window, bool reset) void updateFrameMargins(const QWindow *window, bool reset)
{ {
Q_ASSERT(window); Q_ASSERT(window);
MARGINS margins = {0, 0, 0, 0}; const MARGINS margins = reset ? MARGINS{0, 0, 0, 0} : MARGINS{1, 1, 1, 1};
if (!reset) {
margins.cyTopHeight = 1;
}
WNEF_EXECUTE_WINAPI(DwmExtendFrameIntoClientArea, WNEF_EXECUTE_WINAPI(DwmExtendFrameIntoClientArea,
reinterpret_cast<HWND>(window->winId()), reinterpret_cast<HWND>(window->winId()),
&margins) &margins)
@ -824,13 +821,15 @@ void installHelper(QWindow *window, const bool enable)
window, WinNativeEventFilter::SystemMetric::TitleBarHeight, true, true) window, WinNativeEventFilter::SystemMetric::TitleBarHeight, true, true)
: 0; : 0;
const QMargins margins = {0, -tbh, 0, 0}; const QMargins margins = {0, -tbh, 0, 0};
const QVariant marginsVar = QVariant::fromValue(margins);
window->setProperty("_q_windowsCustomMargins", marginsVar);
#if (QT_VERSION < QT_VERSION_CHECK(6, 0, 0)) #if (QT_VERSION < QT_VERSION_CHECK(6, 0, 0))
QPlatformWindow *platformWindow = window->handle(); QPlatformWindow *platformWindow = window->handle();
if (platformWindow) { if (platformWindow) {
QGuiApplication::platformNativeInterface()->setWindowProperty(platformWindow, QGuiApplication::platformNativeInterface()->setWindowProperty(platformWindow,
QString::fromUtf8( QString::fromUtf8(
"WindowsCustomMargins"), "WindowsCustomMargins"),
QVariant::fromValue(margins)); marginsVar);
} }
#else #else
auto *platformWindow = dynamic_cast<QNativeInterface::Private::QWindowsWindow *>( auto *platformWindow = dynamic_cast<QNativeInterface::Private::QWindowsWindow *>(