无法使用 Qt style_sheet 设置模态 TraitsUI window 的样式

Can't style a modal TraitsUI window with Qt style_sheet

以下视图的样式符合预期

def traits_view(self):
    style_sheet = '''
        QLabel {
            font: 36pt "Verdana";
            margin-left: 12px;
        }

        QPushButton {
            font: 36pt "Verdana";
            margin: 16px;
            padding: 8px
        }
        '''

    return QtView(
        spring,
        Label(self.msg),
        spring,
        buttons=self.buttons,
        height=1.0,
        width=1.0,
        style_sheet=style_sheet,
        )

但是如果我将视图设为模态,样式就会消失:

def traits_view(self):
    style_sheet = '''
        QLabel {
            font: 36pt "Verdana";
            margin-left: 12px;
        }

        QPushButton {
            font: 36pt "Verdana";
            margin: 16px;
            padding: 8px
        }
        '''

    return QtView(
        Label(self.msg),
        buttons=self.buttons,
        kind='modal', # <---- this is the only change
        height=1.0,
        width=1.0,
        style_sheet=style_sheet,
        )

如何设置模态视图的样式?

This is probably a bug,其中 ui 的控件属性在 TraitsUI 尝试设置样式 sheet:

时不可用
Traceback (most recent call last):
  File "test3.py", line 61, in <module>
    alert.configure_traits()
  File "/usr/local/lib/python2.7/dist-packages/traitsui/handler.py", line 459, in configure_traits
    scrollable, **args )
  File "/usr/local/lib/python2.7/dist-packages/traits/has_traits.py", line 2156, in configure_traits
    kind, handler, id, scrollable, args )
  File "/usr/local/lib/python2.7/dist-packages/traitsui/qt4/toolkit.py", line 213, in view_application
    id, scrollable, args )
  File "/usr/local/lib/python2.7/dist-packages/traitsui/qt4/view_application.py", line 83, in view_application
    scrollable, args ).ui.result
  File "/usr/local/lib/python2.7/dist-packages/traitsui/qt4/view_application.py", line 134, in __init__
    args       = self.args )
  File "/usr/local/lib/python2.7/dist-packages/traitsui/qt4/extra/qt_view.py", line 57, in ui
    ui.control.setStyleSheet(self.style_sheet)
AttributeError: 'NoneType' object has no attribute 'setStyleSheet'

解决方法是在控件可用时直接使用 setStyleSheet