Skip to content

style

AYONStyle

Bases: QCommonStyle

AYON QStyle implementation that replaces QSS styling with native Qt painting. Supports widget variants: surface, tonal, filled, tertiary, text, nav, etc.

Source code in client/ayon_ui_qt/style.py
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
class AYONStyle(QCommonStyle):
    """
    AYON QStyle implementation that replaces QSS styling with native Qt
    painting. Supports widget variants: surface, tonal, filled, tertiary,
    text, nav, etc.
    """

    def __init__(self) -> None:
        super().__init__()
        self.model = StyleData()
        self._in_widget_key = False
        self.drawers = {}
        self.sizers = {}
        self.metrics = {}
        self.base_classes = {}
        self.drawer_objs = [
            TooltipDrawer(self),
            LabelDrawer(self),
            LineEditDrawer(self),
            ButtonDrawer(self),
            CheckboxDrawer(self),
            ComboBoxDrawer(self),
            ScrollBarDrawer(self),
            FrameDrawer(self),
            TreeViewDrawer(self),
            TableHeaderDrawer(self),
            ItemViewItemDrawer(self),
            ScrollAreaDrawer(self),
        ]
        for obj in self.drawer_objs:
            self.base_classes.update(obj.base_class)
            if hasattr(obj, "register_drawers"):
                self.drawers.update(obj.register_drawers())
            if hasattr(obj, "register_sizers"):
                self.sizers.update(obj.register_sizers())
            if hasattr(obj, "register_metrics"):
                self.metrics.update(obj.register_metrics())

        # Sort base_classes: most-specific first to guarantee correct widget
        # key resolution order.
        def _specificity_cmp(a, b):
            """Return <0 if `a` is more specific than `b`.

            More specific means: `a` is a (strict) subclass of `b`.
            For unrelated classes, fall back to MRO depth so deeper
            classes still come first, then class name for stability.
            """
            ca, cb = a[1], b[1]
            if ca is cb:
                return 0
            if issubclass(ca, cb):
                return -1  # a before b
            if issubclass(cb, ca):
                return 1  # b before a
            # Unrelated: deeper MRO first, then name for determinism.
            d = len(cb.__mro__) - len(ca.__mro__)
            if d:
                return d
            return (ca.__name__ > cb.__name__) - (ca.__name__ < cb.__name__)

        self.base_classes = dict(
            sorted(self.base_classes.items(), key=cmp_to_key(_specificity_cmp))
        )

    def widget_key(self, w: QWidget | None) -> str:
        if self._in_widget_key or w is None or not isValid(w):
            return ""

        if w:
            # Handle item view widgets - check parent for delegate and exclude
            # ComboBoxItemDelegate
            if hasattr(w, "itemDelegate") and not isinstance(
                w, (QComboBox, QHeaderView)
            ):
                # Calling itemDelegate() is not a simple getter - it can
                # trigger Qt's internal operations that call back into the
                # custom style methods (subElementRect, drawPrimitive,
                # pixelMetric, etc.), each of which calls widget_key() again,
                # creating infinite recursion.
                self._in_widget_key = True
                try:
                    delegate = w.itemDelegate()
                    cbd = delegate and isinstance(
                        delegate, ComboBoxItemDelegate
                    )
                    tvd = delegate and isinstance(
                        delegate, (TreeViewItemDelegate, TableItemDelegate)
                    )
                    if not cbd and not tvd:
                        return "QStyledItemDelegate"
                finally:
                    self._in_widget_key = False
            for name, wtype in self.base_classes.items():
                if issubclass(type(w), wtype):
                    if w.objectName() == "qtooltip_label":
                        return "QToolTip"
                    if isinstance(w, QLabel):
                        p = w.parent()
                        # NOTE: Qt does not use QToolTip but a QLabel (a
                        # private QLabelTip class) !!
                        # if the parent is a widget and it doesn't have a
                        # layout, it could be a tooltip.
                        # Sometimes, objectName() == "qtooltip_label" but the
                        # object name is set when the rect requests are made.
                        if p and isinstance(p, QWidget) and not p.layout():
                            return "QToolTip"
                    return name
        return ""

    def style_widget(self, widget: QWidget) -> None:
        """Apply AYON style to a widget (palette, font, hover tracking)."""
        if isinstance(widget, QWidget):
            variant = getattr(widget, "_variant_str", "default")
            if hasattr(widget, "_style_data"):
                if not widget._style_data:
                    widget._style_data = self.model.get_style(
                        self.widget_key(widget),
                        variant,
                    )
                    widget._style_data.set_context(widget)

            if hasattr(widget, "set_palette"):
                widget.set_palette(
                    self.model.get_style_palette(
                        widget, self.widget_key(widget)
                    )
                )
            else:
                widget.setPalette(QtGui.QPalette(self.model.base_palette))

            if hasattr(widget, "set_font"):
                widget.set_font(QFont(self.model.base_font))
            else:
                widget.setFont(QFont(self.model.base_font))

            # Enable mouse tracking for buttons to receive hover events
            widget.setAttribute(Qt.WidgetAttribute.WA_Hover, True)
            widget.setMouseTracking(True)

            if isinstance(widget, QComboBox):
                widget.setMinimumContentsLength(1)
                widget.setItemDelegate(
                    ComboBoxItemDelegate(parent=widget, style_model=self.model)
                )
                widget.setSizeAdjustPolicy(
                    QComboBox.SizeAdjustPolicy.AdjustToContents
                )
            elif isinstance(widget, QLabel):
                # rounded corner no background.
                widget.setAttribute(
                    Qt.WidgetAttribute.WA_TranslucentBackground, True
                )

    def polish(self, widget) -> None:
        """Polish widgets to enable hover tracking and custom palette."""
        if isinstance(widget, QWidget):
            super().polish(widget)
            self.style_widget(widget)

        elif isinstance(widget, QApplication):
            super().polish(widget)
        else:
            super().polish(widget)

    def drawControl(
        self,
        element: QStyle.ControlElement,
        option: QStyleOption,
        painter: QPainter,
        w: QWidget | None = None,
    ) -> None:
        """Draw control elements (buttons, labels, etc.)."""
        key = enum_to_str(QStyle.ControlElement, element, self.widget_key(w))

        if type(w).__name__ in W_T:
            log.info("  >>  drawControl %s %s", type(w), key)

        try:
            draw_ce_calls = self.drawers[key]
        except KeyError:
            # no custom drawer fallback
            super().drawControl(element, option, painter, w)
            return
        else:
            if isinstance(draw_ce_calls, list):
                for draw_ce in draw_ce_calls:
                    draw_ce(option, painter, w)
            elif callable(draw_ce_calls):
                draw_ce_calls(option, painter, w)
            return

    def drawComplexControl(
        self,
        cc: QStyle.ComplexControl,
        opt: QtWidgets.QStyleOptionComplex,
        p: QPainter,
        w: QWidget | None = None,
    ) -> None:
        key = enum_to_str(QStyle.ComplexControl, cc, self.widget_key(w))
        if type(w).__name__ in W_T:
            log.info("  >>  drawComplexControl %s %s", type(w), key)

        try:
            draw_cc = self.drawers[key]
        except KeyError:
            # no custom drawer fallback
            return super().drawComplexControl(cc, opt, p, w)

        draw_cc(opt, p, w)

    def drawPrimitive(
        self,
        element: QStyle.PrimitiveElement,
        option: QStyleOption,
        painter: QPainter,
        w: QWidget | None = None,
    ) -> None:
        """Draw primitive elements."""

        key = enum_to_str(QStyle.PrimitiveElement, element, self.widget_key(w))
        if type(w).__name__ in W_T:
            log.info("  >>  drawPrimitive %s %s", type(w), key)

        try:
            draw_prim = self.drawers[key]
        except KeyError:
            # Fall back to parent implementation
            super().drawPrimitive(element, option, painter, w)
            return

        draw_prim(option, painter, w)

    def subElementRect(
        self,
        element: QStyle.SubElement,
        option: QStyleOption,
        widget: QWidget | None = None,
    ) -> QRect:
        """Calculate rectangles for sub-elements."""
        key = enum_to_str(QStyle.SubElement, element, self.widget_key(widget))

        if isinstance(widget, QLabel):
            log.debug("%s %s", type(widget).__name__, key)

        try:
            sizer = self.sizers[key]
        except KeyError:
            # Fall back to parent implementation
            # Catch RuntimeError in case widget's C++ object was already
            # deleted
            try:
                if widget is not None:
                    return super().subElementRect(element, option, widget)
                else:
                    return super().subElementRect(element, option)
            except RuntimeError:
                # Widget was deleted, call without it
                return super().subElementRect(element, option)

        return sizer(element, option, widget)

    def subControlRect(
        self,
        cc: QStyle.ComplexControl,
        opt: QtWidgets.QStyleOptionComplex,
        sc: QStyle.SubControl,
        w: QWidget | None = None,
    ) -> QRect:
        key = enum_to_str(QStyle.ComplexControl, cc, self.widget_key(w))

        if isinstance(w, QLabel):
            log.debug("%s %s", type(w).__name__, key)

        try:
            sizer = self.sizers[key]
        except KeyError:
            # Fall back to parent implementation
            return super().subControlRect(cc, opt, sc, w)

        try:
            return sizer(cc, opt, sc, w)
        except ValueError:
            return super().subControlRect(cc, opt, sc, w)

    def pixelMetric(
        self,
        metric: QStyle.PixelMetric,
        opt: QStyleOption | None = None,
        widget: QWidget | None = None,
    ) -> int:
        """Return pixel measurements for various style metrics."""
        key = enum_to_str(QStyle.PixelMetric, metric, self.widget_key(widget))

        if isinstance(widget, QLabel):
            log.debug("%s %s", type(widget), key)

        try:
            metric_func = self.metrics[key]
        except KeyError:
            # Fall back to parent implementation
            return super().pixelMetric(metric, opt, widget)

        return metric_func(metric, opt, widget)

    def styleHint(
        self,
        hint: QStyle.StyleHint,
        opt: QStyleOption | None = None,
        w: QWidget | None = None,
        shret: QtWidgets.QStyleHintReturn | None = None,
    ) -> int:
        """Return style hints for behavior configuration."""

        if hint == QStyle.StyleHint.SH_Button_FocusPolicy:
            return Qt.FocusPolicy.StrongFocus
        elif hint == QStyle.StyleHint.SH_RequestSoftwareInputPanel:
            return 0
        elif hint == QStyle.StyleHint.SH_ComboBox_PopupFrameStyle:
            return QFrame.Shape.NoFrame

        # Fall back to parent implementation
        return super().styleHint(hint, opt, w, shret)

    def sizeFromContents(
        self,
        contents_type: QStyle.ContentsType,
        option: QStyleOption | None,
        contents_size: QtCore.QSize,
        widget: QWidget | None = None,
    ) -> QtCore.QSize:
        """Calculate minimum size requirements for widgets based on their
        content."""
        key = enum_to_str(
            QStyle.ContentsType, contents_type, self.widget_key(widget)
        )

        if isinstance(widget, QLabel):
            log.debug("%s", widget)

        try:
            sizer = self.sizers[key]
        except KeyError:
            if option:
                return super().sizeFromContents(
                    contents_type, option, contents_size, widget
                )
            else:
                # Create a default size if no option is provided
                return QtCore.QSize(100, 32)  # reasonable default
        else:
            return sizer(contents_type, option, contents_size, widget)

__init__()

Source code in client/ayon_ui_qt/style.py
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
def __init__(self) -> None:
    super().__init__()
    self.model = StyleData()
    self._in_widget_key = False
    self.drawers = {}
    self.sizers = {}
    self.metrics = {}
    self.base_classes = {}
    self.drawer_objs = [
        TooltipDrawer(self),
        LabelDrawer(self),
        LineEditDrawer(self),
        ButtonDrawer(self),
        CheckboxDrawer(self),
        ComboBoxDrawer(self),
        ScrollBarDrawer(self),
        FrameDrawer(self),
        TreeViewDrawer(self),
        TableHeaderDrawer(self),
        ItemViewItemDrawer(self),
        ScrollAreaDrawer(self),
    ]
    for obj in self.drawer_objs:
        self.base_classes.update(obj.base_class)
        if hasattr(obj, "register_drawers"):
            self.drawers.update(obj.register_drawers())
        if hasattr(obj, "register_sizers"):
            self.sizers.update(obj.register_sizers())
        if hasattr(obj, "register_metrics"):
            self.metrics.update(obj.register_metrics())

    # Sort base_classes: most-specific first to guarantee correct widget
    # key resolution order.
    def _specificity_cmp(a, b):
        """Return <0 if `a` is more specific than `b`.

        More specific means: `a` is a (strict) subclass of `b`.
        For unrelated classes, fall back to MRO depth so deeper
        classes still come first, then class name for stability.
        """
        ca, cb = a[1], b[1]
        if ca is cb:
            return 0
        if issubclass(ca, cb):
            return -1  # a before b
        if issubclass(cb, ca):
            return 1  # b before a
        # Unrelated: deeper MRO first, then name for determinism.
        d = len(cb.__mro__) - len(ca.__mro__)
        if d:
            return d
        return (ca.__name__ > cb.__name__) - (ca.__name__ < cb.__name__)

    self.base_classes = dict(
        sorted(self.base_classes.items(), key=cmp_to_key(_specificity_cmp))
    )

drawControl(element, option, painter, w=None)

Draw control elements (buttons, labels, etc.).

Source code in client/ayon_ui_qt/style.py
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
def drawControl(
    self,
    element: QStyle.ControlElement,
    option: QStyleOption,
    painter: QPainter,
    w: QWidget | None = None,
) -> None:
    """Draw control elements (buttons, labels, etc.)."""
    key = enum_to_str(QStyle.ControlElement, element, self.widget_key(w))

    if type(w).__name__ in W_T:
        log.info("  >>  drawControl %s %s", type(w), key)

    try:
        draw_ce_calls = self.drawers[key]
    except KeyError:
        # no custom drawer fallback
        super().drawControl(element, option, painter, w)
        return
    else:
        if isinstance(draw_ce_calls, list):
            for draw_ce in draw_ce_calls:
                draw_ce(option, painter, w)
        elif callable(draw_ce_calls):
            draw_ce_calls(option, painter, w)
        return

drawPrimitive(element, option, painter, w=None)

Draw primitive elements.

Source code in client/ayon_ui_qt/style.py
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
def drawPrimitive(
    self,
    element: QStyle.PrimitiveElement,
    option: QStyleOption,
    painter: QPainter,
    w: QWidget | None = None,
) -> None:
    """Draw primitive elements."""

    key = enum_to_str(QStyle.PrimitiveElement, element, self.widget_key(w))
    if type(w).__name__ in W_T:
        log.info("  >>  drawPrimitive %s %s", type(w), key)

    try:
        draw_prim = self.drawers[key]
    except KeyError:
        # Fall back to parent implementation
        super().drawPrimitive(element, option, painter, w)
        return

    draw_prim(option, painter, w)

pixelMetric(metric, opt=None, widget=None)

Return pixel measurements for various style metrics.

Source code in client/ayon_ui_qt/style.py
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
def pixelMetric(
    self,
    metric: QStyle.PixelMetric,
    opt: QStyleOption | None = None,
    widget: QWidget | None = None,
) -> int:
    """Return pixel measurements for various style metrics."""
    key = enum_to_str(QStyle.PixelMetric, metric, self.widget_key(widget))

    if isinstance(widget, QLabel):
        log.debug("%s %s", type(widget), key)

    try:
        metric_func = self.metrics[key]
    except KeyError:
        # Fall back to parent implementation
        return super().pixelMetric(metric, opt, widget)

    return metric_func(metric, opt, widget)

polish(widget)

Polish widgets to enable hover tracking and custom palette.

Source code in client/ayon_ui_qt/style.py
370
371
372
373
374
375
376
377
378
379
def polish(self, widget) -> None:
    """Polish widgets to enable hover tracking and custom palette."""
    if isinstance(widget, QWidget):
        super().polish(widget)
        self.style_widget(widget)

    elif isinstance(widget, QApplication):
        super().polish(widget)
    else:
        super().polish(widget)

sizeFromContents(contents_type, option, contents_size, widget=None)

Calculate minimum size requirements for widgets based on their content.

Source code in client/ayon_ui_qt/style.py
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
def sizeFromContents(
    self,
    contents_type: QStyle.ContentsType,
    option: QStyleOption | None,
    contents_size: QtCore.QSize,
    widget: QWidget | None = None,
) -> QtCore.QSize:
    """Calculate minimum size requirements for widgets based on their
    content."""
    key = enum_to_str(
        QStyle.ContentsType, contents_type, self.widget_key(widget)
    )

    if isinstance(widget, QLabel):
        log.debug("%s", widget)

    try:
        sizer = self.sizers[key]
    except KeyError:
        if option:
            return super().sizeFromContents(
                contents_type, option, contents_size, widget
            )
        else:
            # Create a default size if no option is provided
            return QtCore.QSize(100, 32)  # reasonable default
    else:
        return sizer(contents_type, option, contents_size, widget)

styleHint(hint, opt=None, w=None, shret=None)

Return style hints for behavior configuration.

Source code in client/ayon_ui_qt/style.py
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
def styleHint(
    self,
    hint: QStyle.StyleHint,
    opt: QStyleOption | None = None,
    w: QWidget | None = None,
    shret: QtWidgets.QStyleHintReturn | None = None,
) -> int:
    """Return style hints for behavior configuration."""

    if hint == QStyle.StyleHint.SH_Button_FocusPolicy:
        return Qt.FocusPolicy.StrongFocus
    elif hint == QStyle.StyleHint.SH_RequestSoftwareInputPanel:
        return 0
    elif hint == QStyle.StyleHint.SH_ComboBox_PopupFrameStyle:
        return QFrame.Shape.NoFrame

    # Fall back to parent implementation
    return super().styleHint(hint, opt, w, shret)

style_widget(widget)

Apply AYON style to a widget (palette, font, hover tracking).

Source code in client/ayon_ui_qt/style.py
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
def style_widget(self, widget: QWidget) -> None:
    """Apply AYON style to a widget (palette, font, hover tracking)."""
    if isinstance(widget, QWidget):
        variant = getattr(widget, "_variant_str", "default")
        if hasattr(widget, "_style_data"):
            if not widget._style_data:
                widget._style_data = self.model.get_style(
                    self.widget_key(widget),
                    variant,
                )
                widget._style_data.set_context(widget)

        if hasattr(widget, "set_palette"):
            widget.set_palette(
                self.model.get_style_palette(
                    widget, self.widget_key(widget)
                )
            )
        else:
            widget.setPalette(QtGui.QPalette(self.model.base_palette))

        if hasattr(widget, "set_font"):
            widget.set_font(QFont(self.model.base_font))
        else:
            widget.setFont(QFont(self.model.base_font))

        # Enable mouse tracking for buttons to receive hover events
        widget.setAttribute(Qt.WidgetAttribute.WA_Hover, True)
        widget.setMouseTracking(True)

        if isinstance(widget, QComboBox):
            widget.setMinimumContentsLength(1)
            widget.setItemDelegate(
                ComboBoxItemDelegate(parent=widget, style_model=self.model)
            )
            widget.setSizeAdjustPolicy(
                QComboBox.SizeAdjustPolicy.AdjustToContents
            )
        elif isinstance(widget, QLabel):
            # rounded corner no background.
            widget.setAttribute(
                Qt.WidgetAttribute.WA_TranslucentBackground, True
            )

subElementRect(element, option, widget=None)

Calculate rectangles for sub-elements.

Source code in client/ayon_ui_qt/style.py
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
def subElementRect(
    self,
    element: QStyle.SubElement,
    option: QStyleOption,
    widget: QWidget | None = None,
) -> QRect:
    """Calculate rectangles for sub-elements."""
    key = enum_to_str(QStyle.SubElement, element, self.widget_key(widget))

    if isinstance(widget, QLabel):
        log.debug("%s %s", type(widget).__name__, key)

    try:
        sizer = self.sizers[key]
    except KeyError:
        # Fall back to parent implementation
        # Catch RuntimeError in case widget's C++ object was already
        # deleted
        try:
            if widget is not None:
                return super().subElementRect(element, option, widget)
            else:
                return super().subElementRect(element, option)
        except RuntimeError:
            # Widget was deleted, call without it
            return super().subElementRect(element, option)

    return sizer(element, option, widget)

style_widget_and_siblings(widget, fix_app=False)

Apply AYON style to a widget and its siblings recursively.

Removes any existing stylesheets and applies the AYON QStyle to the given widget and all its sibling widgets (widgets that share the same parent), including all their nested children even if they are in QLayouts.

Parameters:

Name Type Description Default
widget QWidget

The widget whose siblings (and itself) will be styled.

required
fix_app bool

Whether to temporarily remove and restore app stylesheet.

False
Source code in client/ayon_ui_qt/style.py
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
def style_widget_and_siblings(widget: QWidget, fix_app: bool = False) -> None:
    """Apply AYON style to a widget and its siblings recursively.

    Removes any existing stylesheets and applies the AYON QStyle
    to the given widget and all its sibling widgets (widgets that
    share the same parent), including all their nested children
    even if they are in QLayouts.

    Args:
        widget: The widget whose siblings (and itself) will be styled.
        fix_app: Whether to temporarily remove and restore app stylesheet.
    """

    def _collect_widgets(w: QWidget, seen: set[int]) -> None:
        """Recursively collect all widgets including those in layouts."""
        if id(w) in seen:
            return

        seen.add(id(w))
        widgets_to_style.append(w)

        # Collect direct widget children
        for child in w.children():
            if isinstance(child, QWidget):
                _collect_widgets(child, seen)

        # Collect widgets from layouts
        if (layout := w.layout()) is not None:
            for i in range(layout.count()):
                if (item := layout.itemAt(i)) and (
                    item_widget := item.widget()
                ):
                    _collect_widgets(item_widget, seen)

    # Determine root widgets: siblings if parent exists, otherwise just widget
    root_widgets = [widget]

    # Collect all widgets recursively
    seen_widgets: set[int] = set()
    widgets_to_style: list[QWidget] = []
    for w in root_widgets:
        _collect_widgets(w, seen_widgets)

    qss = None
    app = QApplication.instance()
    if fix_app and app and isinstance(app, QApplication):
        qss = copy.copy(app.property("styleSheet"))

    if fix_app and qss and isinstance(app, QApplication):
        app.setStyleSheet("")

    widget.setAttribute(Qt.WidgetAttribute.WA_WindowPropagation, False)

    # Apply style to all collected widgets
    style = get_ayon_style()
    for w in widgets_to_style:
        w.style().unpolish(w)
        w.setStyle(style)

    if fix_app and qss and isinstance(app, QApplication):
        app.setStyleSheet(qss)