Qt 5, get the mouse position in a screen

前端 未结 6 1344
难免孤独
难免孤独 2020-12-17 10:37

First of all, I\'d like to mention that I found that related post How to get the mouse position on the screen in Qt? but it \"just didn\'t work\" for me. I made some tests,

6条回答
  •  遥遥无期
    2020-12-17 11:13

    With QML you can use the properties of the Screen QML Type:

    Screen.virtualX : The x coordinate of the screen within the virtual desktop.

    Screen.virtualY : The y coordinate of the screen within the virtual desktop.

    import QtQuick 2.6
    import QtQuick.Window 2.2
    
    console.log("Pos x : " + Screen.virtualX )
    console.log("Pos y : " + Screen.virtualY )
    

    This work with single screen as well multi-monitor systems.

提交回复
热议问题