app.setStyleSheet performance
-
In PySide calling setStyleSheet at application level seems to slow drastically the execution of the application.
The module cProfile allows to evaluate the impact of setStyleSheet.
Without calling setStyleSheet at application level, opening a subWindow takes 0.091 seconds and cProfile reports :2795 function calls in 0.091 seconds
Ordered by: internal time
ncalls tottime percall cumtime percall filename:lineno(function)
1 0.015 0.015 0.021 0.021 monaffaire.py:13(setupUi)
1 0.011 0.011 0.011 0.011 {method 'sizeHint' of 'PySide.QtGui.QMdiSubWindow' objects}
1 0.005 0.005 0.005 0.005 {method 'show' of 'PySide.QtGui.QWidget' objects}
1 0.005 0.005 0.005 0.005 {method 'findChildren' of 'PySide.QtCore.QObject' objects}
1 0.005 0.005 0.005 0.005 {method 'setTable' of 'PySide.QtSql.QSqlTableModel' objects}When adding a dumb stylesheet by app.setStyleSheet("/* */"), the same subWindow opens in 0.193 seconds and cProfile reports :
2978 function calls in 0.193 seconds
Ordered by: internal time
ncalls tottime percall cumtime percall filename:lineno(function)
1 0.050 0.050 0.051 0.051 {method 'addSubWindow' of 'PySide.QtGui.QMdiArea' objects}
1 0.021 0.021 0.021 0.021 {method 'setWidget' of 'PySide.QtGui.QMdiSubWindow' objects}
1 0.021 0.021 0.021 0.021 {method 'sizeHint' of 'PySide.QtGui.QMdiSubWindow' objects}
1 0.019 0.019 0.042 0.042 monaffaire.py:13(setupUi)
4 0.018 0.004 0.018 0.004 {method 'addTab' of 'PySide.QtGui.QTabWidget' objects}Is there a way to integrate stylesheet at application level without reducing the performance ?
When calling setStyleSheet at QWidget level, no loss of performance seems to occur, but this way does not permit to regroup all stylesheet instructions in one external qss file. -
Hi,
Putting your stylesheet at the application level (especially if the one your wrote) means that each and every widget might be customised which requires changing the style used to draw the widget. So you should be careful with what you put in your stylesheet.