开发者

Qt grabWindow coordinates shifted from GetCursorPos and GetWindowRect

In Qt, when I use the QPix开发者_如何转开发map::grabWindow(hwnd,x,y,h,w) function, the coordinates are shifted slightly, when compared to the coordinates using the windows api functions GetCursorPos and GetWindowRect.

i.e. (0,0) from the point of view of GetCursorPos and GetWindowRect is at the very top left of the toolbar at the top of the window.

But (0,0) for QPixmap::grabWindow is more "inside" (i.e. ignoring the window frame).

How can I make these 2 coordinates consistent? Especially since the user might have different thicknesses for the window frame?


I agree with Kotti.... if you are using Qt, stick to Qt calls only. You can probably replace calls to GetCursorPos() with QCursor::pos() and GetWindowRect() with window()->geometry().

That said, if you must call the Windows API directly, you could figure out the offset between the two co-ordinate systems dynamically, by calling the equivalent function in each API with the same arguments and subtracting the results from each other. Then you could use that delta to translate from one co-ordinate system to the other as necessary. That would work, but it would be a pain, so only do it if you absolutely must.


I think the best idea would be sticking to only one type of coordinates. This way you won't bother yourself with questions like "Are these coordinates from winapi function of from grabWindow function", "Do I have to convert these coordinates into first type or second type".

Of course, I might be wrong, but I tend to think there is a good approach or ability to redesign your app that will only be using one of mentioned coordinate types.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜