Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

开启无边框窗口后鼠标位置映射异常 #24

Open
Italink opened this issue Jan 14, 2024 · 5 comments
Open

开启无边框窗口后鼠标位置映射异常 #24

Italink opened this issue Jan 14, 2024 · 5 comments
Assignees
Labels
bug Something isn't working

Comments

@Italink
Copy link

Italink commented Jan 14, 2024

操作系统:Win10 22H2
Qt版本:6.7.0
使用如下代码测试:

import QtQuick 
import QtQuick.Window 
import QtQuick.Controls 
import Qt.labs.platform 
import QWindowKit

Window {
    id: window
    width: 800
    height: 600
    title: qsTr("Hello, world!")
    Component.onCompleted: {
        windowAgent.setup(window)
        window.visible = true
    }

    WindowAgent {
        id: windowAgent
    }

    MouseArea{
        anchors.fill: parent
        onPressed: (mouse)=>{
               var global = mapToGlobal(mouse.x,mouse.y)
               helper.setCursorPos(global.x,global.y)
               var local = mapFromGlobal(global.x,global.y)
               console.log("mouse:",mouse.x,mouse.y,"  global:",global," local:",local)
        }
    }

helper.setCursorPos(global.x,global.y) 是一个C++提供的函数,它仅仅是调用QCursor::setPos(x, y)
目前发现开启无边框窗口后,mapToGlobal得到的鼠标位置跟实际的鼠标位置会相差一个标题栏的高度,但是再使用mapFromGlobal还原得到的本地坐标确实正确的

表现情况如下:
asd

@Italink
Copy link
Author

Italink commented Jan 14, 2024

初步定位到CustomMargins会影响到鼠标映射
image

@wangwenx190
Copy link
Collaborator

我们手动调用了setCustomMargins,就是为了消除这个问题

@wangwenx190
Copy link
Collaborator

不调用肯定是不行的,我们必须通知Qt我们已经修改了margins,否则Qt内部维护的数据与我们不一致,会产生很多bug

@Italink
Copy link
Author

Italink commented Jan 15, 2024

明白,你们修改Margin应该是为了解决Render的问题吧?
但是CustomMargin会影响到Window的Geometry,从而导致MapToGlobal异常,虽然我能手动去矫正这个坐标的偏差,但这会不会给一些程序控件增加一些潜在的隐患?

@wangwenx190
Copy link
Collaborator

你说的也很有道理,可能确实会导致暗病,我和 @SineStriker 再合计一下

@wangwenx190 wangwenx190 self-assigned this Jan 15, 2024
@wangwenx190 wangwenx190 added the bug Something isn't working label Jan 15, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants