enthought / enthought/traitsui
QtView style sheet not taken into account with kind='modal'
- Dominant language
- Python
- Stars
- 306
- Forks
- 99
- PR merge metrics
- No merged PRs in 30d
Description
Using this code:
from traits.api import HasTraits, Int, Instance
from traitsui.qt4.extra.qt_view import QtView
class A(HasTraits):
a = Int
class B(HasTraits):
b = Instance(A,())
b = B()
b.configure_traits(view = QtView('b', style_sheet='font: 18pt "Verdana"'))
the style sheet is used. If the last line is changed to
b.configure_traits(view = QtView('b', style_sheet='font: 18pt "Verdana"'), kind='modal')
it is not.
I could fix this by changing and renaming **ui** in traitsui\qt4\extra\qt_view.py:
def ui(self, context, parent=None, kind=None, view_elements=None,
handler=None, id='', scrollable=None, args=None):
ui = super(QtView, self).ui(context, parent, kind, view_elements,
handler, id, scrollable, args)
if self.style_sheet:
ui.control.setStyleSheet(self.style_sheet)
if self.style_sheet_path:
try:
with open(self.style_sheet_path, 'r') as f:
ui.control.setStyleSheet(f.read())
except IOError:
logger.exception("Error loading Qt style sheet")
if len(self.tab_order) >= 2:
previous = self._get_editor_control(ui, self.tab_order[0])
for i in xrange(1, len(self.tab_order)):
current = self._get_editor_control(ui, self.tab_order[i])
QtGui.QWidget.setTabOrder(previous, current)
previous = current
return ui
to the following:
def _use_style_sheet(self, ui): # changed the name
# The rest is the same except the call to superclass' ui
if self.style_sheet:
ui.control.setStyleSheet(self.style_sheet)
if self.style_sheet_path:
try:
with open(self.style_sheet_path, 'r') as f:
ui.control.setStyleSheet(f.read())
except IOError:
logger.exception("Error loading Qt style sheet")
if len(self.tab_order) >= 2:
previous = self._get_editor_control(ui, self.tab_order[0])
for i in xrange(1, len(self.tab_order)):
current = self._get_editor_control(ui, self.tab_order[i])
QtGui.QWidget.setTabOrder(previous, current)
previous = current
and by changing the first lines of **display_ui** in traitsui\qt4\ui_base.py :
@staticmethod
def display_ui(ui, parent, style):
"""Display the UI."""
ui.owner.init(ui, parent, style)
ui.control = ui.owner.control
ui.control._parent = parent
if hasattr(ui.view,'style_sheet'): # added
ui.view._use_style_sheet(ui) # added
....
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.