Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Editing qss stylesheet programmatically

Editing qss stylesheet programmatically

Scheduled Pinned Locked Moved Solved General and Desktop
7 Posts 2 Posters 2.4k Views
  • 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.
  • TirolelT Offline
    TirolelT Offline
    Tirolel
    wrote on last edited by
    #1

    Hi everyone.

    I'm looking into a solution or idea how to edit an exiting .qss file. I have 4-5 qss files which I want to edit the file in Gui without doing manually.

    fx. I have bunch of items and I want to edit the QLabel's color.

    ....
    QLabel
    {
    ...
    color: #aaaaaa;
    ....
    }
    ....

    How am I going to archieve this?

    raven-worxR 1 Reply Last reply
    0
    • TirolelT Tirolel

      Hi everyone.

      I'm looking into a solution or idea how to edit an exiting .qss file. I have 4-5 qss files which I want to edit the file in Gui without doing manually.

      fx. I have bunch of items and I want to edit the QLabel's color.

      ....
      QLabel
      {
      ...
      color: #aaaaaa;
      ....
      }
      ....

      How am I going to archieve this?

      raven-worxR Offline
      raven-worxR Offline
      raven-worx
      Moderators
      wrote on last edited by
      #2

      @Tirolel

      1. get the qss from the widget using QWidget::stylesheet()
      2. set the returned qss to a QTextEdit and edit it
      3. when finished set the qss QTextEdit::toPlainText() back to the same widget where you got it from using QWidget::setStyleSheet()

      --- SUPPORT REQUESTS VIA CHAT WILL BE IGNORED ---
      If you have a question please use the forum so others can benefit from the solution in the future

      1 Reply Last reply
      0
      • TirolelT Offline
        TirolelT Offline
        Tirolel
        wrote on last edited by Tirolel
        #3

        Yea but the issue here is that the "user" have to edit the qss manually. What I want to archieve is in my GUI I have few QLineEdit with qColorDialog (For QLabel, textsize and background) . So user needs only to pick a color and "somehow" replace the chosen color.
        fx. if I Choose red in color picker, It have to update the qss with the value I have picked.

        raven-worxR 1 Reply Last reply
        0
        • TirolelT Tirolel

          Yea but the issue here is that the "user" have to edit the qss manually. What I want to archieve is in my GUI I have few QLineEdit with qColorDialog (For QLabel, textsize and background) . So user needs only to pick a color and "somehow" replace the chosen color.
          fx. if I Choose red in color picker, It have to update the qss with the value I have picked.

          raven-worxR Offline
          raven-worxR Offline
          raven-worx
          Moderators
          wrote on last edited by raven-worx
          #4

          @Tirolel

          QColor color = QColorDialog::getColor(...);
          
          widget->setStyleSheet( QString(
          "QLabel {"
          "..."
          "color: %1;"
          "...."
          "}"
          ).arg( color.name() ) );
          

          If the qss can be predicted, than there is no way around parsing the qss and replace the value.

          --- SUPPORT REQUESTS VIA CHAT WILL BE IGNORED ---
          If you have a question please use the forum so others can benefit from the solution in the future

          1 Reply Last reply
          0
          • TirolelT Offline
            TirolelT Offline
            Tirolel
            wrote on last edited by
            #5

            @raven-worx

            I see. But what would the default value of color be before setting the color? can I do sth like this

            "color: %1#fffffff;"
            
            raven-worxR 1 Reply Last reply
            0
            • TirolelT Tirolel

              @raven-worx

              I see. But what would the default value of color be before setting the color? can I do sth like this

              "color: %1#fffffff;"
              
              raven-worxR Offline
              raven-worxR Offline
              raven-worx
              Moderators
              wrote on last edited by
              #6

              @Tirolel
              the default color is decided by the platform style.
              So you should ask the widget's QPalette:

              widget->palette().color( QPalette::Text );
              

              Which color group excactly depends on the widget type. But i think mostly it should be QPalette::Text for the text.

              In my example the %1will be replaced with the value passed to arg()
              So you need to remove it, when you are not calling the arg() method on the string.

              --- SUPPORT REQUESTS VIA CHAT WILL BE IGNORED ---
              If you have a question please use the forum so others can benefit from the solution in the future

              1 Reply Last reply
              0
              • TirolelT Offline
                TirolelT Offline
                Tirolel
                wrote on last edited by
                #7

                Okay thanks a lot!

                I will try to see if I can get it to work :)

                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 Extensions
                • Unsolved