Important: Please read the Qt Code of Conduct -

[SOLVED] Change stysheet at runtime

  • Hello guys!

    I read a lot of topic-relevant tasks but I did not find the answer for my question (Maybe I can not understand the answers 'cause those are too clever :D )

    I would like to update my QLabel objects inside a loop during runtime.
    I am designing an app to step through a list of folders and execute a command with QProcess. Next to the window I show a list of these folders and I would like to change the stylesheet "font-weight: bold;" for the name of the current foder for indicate where the progam is now.
    But my problem is that the ALL stylesheet changes will be executed AFTER the loop went through ALL the folders.

    I use the setStyleSheet() function, and I tried with style()->unpolish(); style()->polish(); update(); methods too but nothing happened during execution.

    Can somebody explain a possible solution or show an example from scratch how can I use attributes for my problem?

    Have a nice day :)

  • Moderators

    You're probably going at it the wrong way. It's not that the stylesheet is not being applied, it's probably your loop that blocks the UI thread and doesn't allow it to apply changes.

    A poor and quick solution would be to call qApp->processEvents() in your loop, but a better one would be to make the thing that is done in the loop an asynchronous action that emits an update signal.

  • Hi!

    You are right!
    I changed my loop via QProcess to asynchronous and step in another method into the next folder in the SLOT what I connected to the SIGNAL of QProcess finished(int).

    Thank you and I hope it will help to everyone in the future.

    Best regards

Log in to reply