X-AnyLabeling icon indicating copy to clipboard operation
X-AnyLabeling copied to clipboard

UI flickers when adaptive font scaling oscillates near a window size threshold

Open ljh725 opened this issue 1 month ago • 1 comments

Maximized UI flickers when adaptive font scaling oscillates near a size threshold

Environment

  • OS: Windows
  • Python: 3.12.12
  • Application: a locally modified 4.2.1 checkout; the density calculation below also appears in the official main branch. The complete official checkout has not yet been tested independently.

Observed behavior

On one Windows machine, maximizing the application causes UI components to repeatedly grow and shrink. The image canvas also moves after an image is loaded. Restoring the window stops the oscillation; disabling the automatic UI-density update stops it in both states. No particular image is needed to trigger the UI behavior.

Isolated reproduction

Using the original _update_ui_density implementation in the local 4.2.1 UI and Qt's offscreen platform, resize the top-level window to approximately 2300 × 1114 Qt logical pixels. At that size, repeated timer callbacks produced this sequence:

widget height 1063, scale 1.000 -> 1.125
widget height 1061, scale 1.125 -> 1.000
widget height 1063, scale 1.000 -> 1.125
widget height 1061, scale 1.125 -> 1.000

The exact triggering dimensions depend on font metrics and layout; maximizing is not required for the isolated reproduction. The tests used the original density function with the remaining UI from a modified local checkout, rather than a pristine official checkout.

Likely cause

LabelingWidget._update_ui_density() derives a quantized scale from self.width() and self.height(), then calls apply_application_font(). Changing the global font triggers a layout change, which changes the same widget's available height and causes resizeEvent() to schedule another density update. Near the 1.0 / 1.125 boundary (height 1062.5), the 2-pixel layout change crosses the boundary in both directions.

As a control, suppressing apply_application_font stopped the loop in this experiment; suppressing tools.setUiScale did not. Canvas auto-fit can respond to the repeated resize events, causing the displayed image to move as well.

Possible fix

Calculate density from a stable top-level window size rather than the child widget whose geometry changes in response to font scaling, or introduce appropriate hysteresis. A local change using self.window().width() and self.window().height() settled after one scale change at the tested size; this is a candidate fix and may need additional testing across displays and layouts.

Expected behavior

At a fixed window size, the interface density should settle and the UI and canvas should remain stable.

ljh725 avatar Oct 28 '26 03:10 ljh725

https://github.com/user-attachments/assets/7bf6b455-1875-41c8-ad61-8c511bf4f99c

ljh725 avatar Oct 28 '26 03:10 ljh725