Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Trying to save the stylesheet options of an object after a new one has been created
Qt 6.12 LTS is out! See what's new in the release blog

Trying to save the stylesheet options of an object after a new one has been created

Scheduled Pinned Locked Moved Unsolved General and Desktop
3 Posts 3 Posters 641 Views 2 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • Dummie1138D Offline
    Dummie1138D Offline
    Dummie1138
    wrote on last edited by
    #1

    Hi. I have an object (which is tied to a ui file) and a function that changes the stylesheet of said object such that the text would be in red. This object will be closed regularly and I would like to be able to save the modified stylesheet such that the text would remain red after I reopen the stylesheet. My stylesheet is defined in the ui file, and not the cpp file.

    The immediate method I can think of to "save" said stylesheet would be to create another object (maybe a QString that saves 'red', 'blue', 'black') and have it act as an input to the color changer function, then run the color changer everytime this object is created. However, I was wondering whether there is a simple way I could modify and save this new stylesheet such that I don't have to run this color changing function everytime I create the object.

    Please let me know if more information is required.

    JonBJ 1 Reply Last reply
    0
    • Dummie1138D Dummie1138

      Hi. I have an object (which is tied to a ui file) and a function that changes the stylesheet of said object such that the text would be in red. This object will be closed regularly and I would like to be able to save the modified stylesheet such that the text would remain red after I reopen the stylesheet. My stylesheet is defined in the ui file, and not the cpp file.

      The immediate method I can think of to "save" said stylesheet would be to create another object (maybe a QString that saves 'red', 'blue', 'black') and have it act as an input to the color changer function, then run the color changer everytime this object is created. However, I was wondering whether there is a simple way I could modify and save this new stylesheet such that I don't have to run this color changing function everytime I create the object.

      Please let me know if more information is required.

      JonBJ Offline
      JonBJ Offline
      JonB
      wrote on last edited by JonB
      #2

      @Dummie1138
      You will indeed to save it yourself, the code generated (via uic) from your .ui file is for as it was when you designed it and hence will not contain the modification the next time you run the Qt program.

      Save the current widget->styleSheet() string, or whatever information you want to be able to redo what you need to do. You might save it to settings via QSettings. When your program starts, look for this saved value and if found apply to your widget during startup.

      1 Reply Last reply
      0
      • SGaistS Offline
        SGaistS Offline
        SGaist
        Lifetime Qt Champion
        wrote on last edited by
        #3

        Hi,

        Shouldn't the change of color rather depend on the state of the widget ? You can use a dynamic property.

        Doing so you will need only one stylesheet without the need to change it yourself.

        Interested in AI ? www.idiap.ch
        Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

        1 Reply Last reply
        0

        • Login

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • Users
        • Groups
        • Search
        • Get Qt
        • Unsolved