Clear Dynamic Properties

  • Hello all,

    As I am aware, I can set the dynamic properties by using setProperty function.

    For example, I would have a stylesheet which appears to be like this -


    So, in my code I would set something like
    myLabel->setProperty("BlueColorLabel", "true");

    During run time, if I want change the color of my label, I may have to do something like this
    myLabel->setProperty("BlueColorLabel", "false");
    myLabel->setProperty("YellowColorLabel", "true");

    This would remove the previous property and set the new one.

    Here is my question.
    Here I know the property value, so I could easily set it to false.

    Is there a way that will help me to clear all properties without specifying them or even without knowing them?

    Thank you,

  • Lifetime Qt Champion


    Use dynamicPropertyNames to get all dynamic properties and then loop through and call setProperty with an invalid QVariant to remove them.

  • Hi Sam,

    After I ask the question, I exactly tried the same dynamicPropertyNames and achieved the result I wanted.

    Thank you!


Log in to reply

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.