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. [SOLVED] Adding consecutive stylesheets to widget
Forum Updated to NodeBB v4.3 + New Features

[SOLVED] Adding consecutive stylesheets to widget

Scheduled Pinned Locked Moved General and Desktop
5 Posts 2 Posters 1.7k Views 1 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.
  • H Offline
    H Offline
    holygirl
    wrote on last edited by
    #1

    Hello all!

       I'm using a single stylesheet to apply styles to all my widgets. My qss code is,
    

    @
    QLabel#heading
    {
    font-size: 28px;
    font-weight: bold;
    font-family: "Arial Narrow";
    }

    QLabel#colorgreen
    {
    color: green;
    }

    QLabel#colorblack
    {
    color:black;
    }
    @

    And in my source file, I want to call both 'heading' and 'colorgreen' or ' colorblack' depending on my color requirements. I have,

    @
    ui->channel_name->setObjectName("heading");
    ui->channel_name->setStyleSheet("");
    ui->channel_name->setObjectName("blackcolor");
    ui->channel_name->setStyleSheet("");
    @

    However, only the color changes to black. The styles under 'heading' is not applied. Does anyone know why? Please help me out.
    Thanks.

    1 Reply Last reply
    0
    • F Offline
      F Offline
      Fahmy
      wrote on last edited by
      #2

      It is because your using 'id' in every CSS element. So you need all the properties to be declare under the id. Unless you using id and class together.

      @QLabel #colorgreen
      {
          font-size: 28px;
          font-weight: bold;
          font-family: "Arial Narrow"
          color: green;
      }
       
      QLabel #colorblack
      {
          font-size: 28px;
          font-weight: bold;
          font-family: "Arial Narrow"
          color:black;
      }@
      

      Stay hungry, stay foolish.

      1 Reply Last reply
      0
      • H Offline
        H Offline
        holygirl
        wrote on last edited by
        #3

        I don't want to club all the properties together. I will be using a different assortment of properties each time. Clubbing them together will result in heavy repetition of code. Is there any other way out?

        1 Reply Last reply
        0
        • F Offline
          F Offline
          Fahmy
          wrote on last edited by
          #4

          Hmmm...I think in this case you should using CSS like this:

          @QLabel {
          font-size: 28px;
          font-weight: bold;
          font-family: "Arial Narrow"
          }

          #colorgreen
          {
          color: green;
          }

          #colorblack {
          color:black;
          }@

          It is basically mean all QLabel will have all properties in QLabel {..} .

          And when you set objectName either (#colorgreen or #colorblack) then it will change the color -- also combine with all QLabel's properties.

          Stay hungry, stay foolish.

          1 Reply Last reply
          0
          • H Offline
            H Offline
            holygirl
            wrote on last edited by
            #5

            Ah yes! Why didn't I think of this? Thank you so much for the solution Fahmy.

            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