Last active
August 9, 2024 08:28
-
-
Save kuanyui/16f36f75cbc78891d91ff33cc3572d8e to your computer and use it in GitHub Desktop.
QtAV中的VideoOutput2在不同螢幕解析度下的滑鼠座標 (QtMultimedia內建的VideoOutput也許也適用,但我他媽的一個影片也沒播成功過所以無法測試)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Item { | |
id: videoArea | |
anchors.top: parent.top | |
width: parent.width | |
height: parent.height - panelRectangle.height | |
VideoOutput2 { | |
id: videoOutput | |
anchors.fill: parent | |
source: player | |
} | |
MediaPlayer { | |
id: player | |
volume: 0 | |
source: "file:///Users/onohiroko/movie.mp4" | |
} | |
MouseArea { | |
anchors.fill: videoOutput // 指向 QtAV2 的 VideoOutput2 | |
onPressed: function (mouse) { | |
player.play(); | |
// MouseArea拿到的x,y不是真正物理上pixel的數量(VideoOutput2的輸出是以物理pixel為基準的樣子),所以要乘上ratio | |
var x = mouse.x * Screen.devicePixelRatio | |
var y = mouse.y * Screen.devicePixelRatio | |
console.log("=================================================================") | |
// 這兩個沒有啥屁用,因為其座標系統不包含影片旁的黑框部分 | |
console.log("[video source rect ]", videoOutput.sourceRect) | |
console.log("[sourceP to itemP ]", videoOutput.mapPointToItem(Qt.point(x, y))) | |
// 以下座標是以整個VideoOutout為範圍,也就是包含影片黑框部分 | |
console.log("[video content rect]", videoOutput.contentRect) // 影片在畫面上render出的長寬,(x黑框, y黑框, 影片w, 影片h) | |
console.log("[video reoslution ]", player.metaData.resolution) // 影片檔實際長寬,在同一影片中永遠不會變 | |
console.log("[mouse event ]", x, y) // 在VideoOutput2這個QML Item中,mouse的相對位置,且ratio計算過 | |
var mouseOnSource = videoOutput.mapPointToSource(Qt.point(x, y)) // mouse在「影片檔本身實際長寬」中的相對位置 | |
console.log("[mouse on Source ]", mouseOnSource) // [同上] | |
console.log("[mouse on QML Item ]", videoOutput.mapPointToItem(Qt.point(mouseOnSource.x , mouseOnSource.y))) // 從「影片檔本身座標」換算回QML Item的座標(mouse event) | |
} | |
onDoubleClicked: applicationWindow.toggleFullScreen() | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment