From 07290f9aeb9a00dc4fef29541f1d86eed271b2f2 Mon Sep 17 00:00:00 2001 From: Yuhang Zhao <2546789017@qq.com> Date: Mon, 8 Mar 2021 15:17:01 +0800 Subject: [PATCH] Fix coordinate bug for FramelessHelper too Signed-off-by: Yuhang Zhao <2546789017@qq.com> --- framelesshelper.cpp | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/framelesshelper.cpp b/framelesshelper.cpp index 89e7342..d693e78 100644 --- a/framelesshelper.cpp +++ b/framelesshelper.cpp @@ -1,7 +1,7 @@ /* * MIT License * - * Copyright (C) 2020 by wangwenx190 (Yuhang Zhao) + * Copyright (C) 2021 by wangwenx190 (Yuhang Zhao) * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal @@ -25,11 +25,10 @@ #include "framelesshelper.h" #if (QT_VERSION >= QT_VERSION_CHECK(5, 15, 0)) -#include -#include -#include -#include -#include +#include +#include +#include +#include FramelessHelper::FramelessHelper(QObject *parent) : QObject(parent) {} @@ -101,6 +100,7 @@ void FramelessHelper::setResizable(const QWindow *window, const bool val) void FramelessHelper::removeWindowFrame(QWindow *window) { Q_ASSERT(window); + // TODO: check whether these flags are correct for Linux and macOS. window->setFlags(Qt::Window | Qt::FramelessWindowHint | Qt::WindowSystemMenuHint | Qt::WindowMinMaxButtonsHint | Qt::WindowTitleHint); // MouseTracking is always enabled for QWindow. @@ -183,9 +183,15 @@ bool FramelessHelper::eventFilter(QObject *object, QEvent *event) } const auto mapOriginPointToWindow = [](const QObject *obj) -> QPointF { Q_ASSERT(obj); + if (!obj) { + return {}; + } QPointF point = {obj->property("x").toReal(), obj->property("y").toReal()}; for (QObject *parent = obj->parent(); parent; parent = parent->parent()) { point += {parent->property("x").toReal(), parent->property("y").toReal()}; + if (parent->isWindowType()) { + break; + } } return point; };