Qt6.8.2 Android: Mouse coordinates inside a QDialog window are wrong.
-
I wrote an application where I use a QDialog for authentication. The app first draws some objects on the central widget and then opens the dialog. So far so well. But every click or touch inside the dialog has wrong mouse coordinates. The number of pixels it is wrong depends on the resolution of the display.
On the screenshot below you can see the red point which should be x, y: 0, 0. But it is 22, 109 on a Pixel 9 Pro with API 35. On other devices this point is different, depending on the resolution of the display.
I tried to write a workaround working on all devices by catching the mouse press and correcting this values. But I can't find a way to calculate the x, y values difference. For this particular phone I get the following dimensions:- Notch height: 156 real pixel: By factor 3.0 this is 52.
- Real dimensions: 1280 x 2784 -- Height without notch: 2628
- Using factor 3 to calculate virtual dimensions.
- Available size: 427 x 876
- Virtual size: 427 x 952 (inclusive notch)
The dialog box is located as follows:
- Geometry: left: 0 , top: 0 , width: 280 , height: 144
- top left corner relative to parent: left: 73 , top: 366 --> Not sure if this is correct!
- Title height: 18 --> Allthough on Android there is no title it reports me this height for it!
The dialog box was created with QtCreator and is defined in an UI file.
This problem exists only on Android. On other systems it works as expected.
Does anybody know how I can calculate the difference of reported mouse coordinates to the expected ones? -
Just for information: I implemented a workaround by using a QWidget instead of the QDialog. This works mostly as expected. Only drawback is that I can't make it modal. The background objects are reacting while the Dialog is in forground. But in this special case it doesn't matter.
-
I encountered a similar problem in my effort to port a desktop app (developed on Ubuntu 20 / Qt 6.8.0) to Android. The problem seems to have gone away for me when I removed all the vertical spacers from the layouts within my QDialog.