Repository navigation
Conversation
The Qt preview set its GL viewport from the widget's logical size, but the widget's framebuffer is in device pixels. At a 200% scale the scene was drawn into the lower left quarter of the widget (LinuxCNC#4860). The GTK preview already follows the scale factor; the Qt one did not. winfo_width/winfo_height now return device pixels, line widths and the DRO font follow the scale factor, and click-to-select scales the mouse position to match. The Qt vismach widget gets the same viewport fix. Panning converts the mouse movement, which is in logical pixels, with a new winfo_scale() hook in glnav, so the scene tracks the cursor instead of moving at 1/scale speed. It defaults to 1.0; the Qt and GTK previews override it.
Qt5 leaves high-DPI scaling off unless asked. On a scaled display the fonts then follow the screen DPI while widget sizes stay in raw pixels, so point-sized text outgrows its widgets: at 192 dpi qtdragon opened at 1470x892 with most button labels clipped. Qt6 always scales. Set AA_EnableHighDpiScaling and AA_UseHighDpiPixmaps before the application is created, on Qt5 only.
| self.select(x, y) | ||
| # Events are logical pixels, the pick target is device pixels. | ||
| scale = self.winfo_scale() | ||
| self.select(x * scale, y * scale) |
There was a problem hiding this comment.
qtvcp's GCodeGraphics overrides select_fire in lib/python/qtvcp/widgets/gcode_graphics.py and still calls self.select(x, y), so qtdragon and qtaxis don't get this scaling. At 200% clicking a program line selects nothing in qtdragon; with the scaling in the override it works. Could the override get it too, or call this one after its own checks?
| import qtpy | ||
| if qtpy.QT5: | ||
| QtWidgets.QApplication.setAttribute(QtCore.Qt.AA_EnableHighDpiScaling) | ||
| QtWidgets.QApplication.setAttribute(QtCore.Qt.AA_UseHighDpiPixmaps) |
There was a problem hiding this comment.
Qt5 rounds the scale factor to the nearest integer, so a 150% desktop becomes 2x and a 1920x1080 screen looks like 960x540 to qtvcp. Adding QtGui.QGuiApplication.setHighDpiScaleFactorRoundingPolicy(QtCore.Qt.HighDpiScaleFactorRoundingPolicy.PassThrough) here gives 1.5, same as Qt6's default. Worth adding?
| # Device pixels: the framebuffer is allocated at the window scale (HiDPI) | ||
| def winfo_width(self): | ||
| return self.geometry().width() | ||
| return round(self.geometry().width() * self.devicePixelRatioF()) |
There was a problem hiding this comment.
With winfo_* now in device pixels, the vismach HUD text (primitives.py) stays at its 1x pixel size, so at 200% it is half size relative to the window. Maybe pass scale= to use_pango_font there as in qt5_graphics?
Fixes #4860.
Preview drawn into a quarter of the widget
The Qt preview set its GL viewport from the widget's logical size, but the framebuffer is in device pixels. At 200% the scene landed in the lower left quarter, as in the issue's qtdragon screenshots. The GTK preview already follows the scale factor; this brings the Qt one in line:
winfo_width/winfo_heightreturn device pixelswinfo_scale()hook inglnav(default 1.0), overridden by the Qt and GTK previews, so the scene tracks the cursor instead of moving at 1/scale speedOversized text on Qt5
Qt5 leaves high-DPI scaling off, so on a scaled display fonts follow the screen DPI while widget sizes stay in raw pixels. At 192 dpi qtdragon opened at 1470x892 with most button labels clipped.
qtvcpnow setsAA_EnableHighDpiScalingandAA_UseHighDpiPixmapson Qt5 only; Qt6 always scales.Testing
PyQt5 5.15 under XWayland at 192 dpi:
sim_panel,test_panel,vismach_mill_xyz: fine, vismach fills its windowNot tested: Qt6, panning and click-to-select by hand, and the GTK panning change (it returns 1 at scale 1, so nothing changes there).
Known issue
A qtvcp panel embedded in AXIS with
-x(configs/sim/axis/qtvcp/qtvismach_tab.ini) is now 1600x1200 instead of 800x600 at 192 dpi and overflows its tab, since AXIS does not resize the embedded panel. Not addressed here.