Does the use of styleSheets in a dynamic manner add a lot of computation

后端 未结 3 656
半阙折子戏
半阙折子戏 2020-12-29 13:56

I have about 40 buttons that are also indicators (On or Off) and once a second I refresh the color of these indicators depending on the state. I do this by changing the sty

3条回答
  •  一生所求
    2020-12-29 14:47

    Yes. I found that with Qt 4.6.2 on Linux, setting a stylesheet to change the colour of the text on a QLabel is very slow.

    The dynamic stylesheet looked like a great solution but for me, the necessary setStyle() was just as expensive as setStyleSheet()!

    After much experimentation, I found this alternative to be at least twice as quick, and usually more than 50 times as quick:

    QPalette palette = lbl->palette();
    palette.setColor(QPalette::WindowText, Qt::gray);
    lbl->setPalette(palette);
    

    Depending on how your (static) stylesheet is set up, you'd have to replace QPalette::WindowText with QPalette::Window or QPalette::Button. See the QPalette documentation for details.

提交回复
热议问题