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. Inter-changeable style sheets, are they possible?
Forum Updated to NodeBB v4.3 + New Features

Inter-changeable style sheets, are they possible?

Scheduled Pinned Locked Moved General and Desktop
11 Posts 2 Posters 3.5k 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.
  • D Offline
    D Offline
    Dolphin
    wrote on last edited by
    #1

    I can see that the style sheet code I have put into gui via Qt Designer is put into the project.ui xml document and is not actually its own file as per CSS.

    What if I want more than one look and feel for a project? Is there any way to have multiple 'style sheets' like I would do with CSS so styles can be interchanged?

    1 Reply Last reply
    0
    • sierdzioS Offline
      sierdzioS Offline
      sierdzio
      Moderators
      wrote on last edited by
      #2

      Yes. You can have many style sheets stored in files on your disk, and then just load them using QWidget::setStyleStheet().

      (Z(:^

      1 Reply Last reply
      0
      • D Offline
        D Offline
        Dolphin
        wrote on last edited by
        #3

        Doh! How did I miss that?? Thanks :-)

        1 Reply Last reply
        0
        • sierdzioS Offline
          sierdzioS Offline
          sierdzio
          Moderators
          wrote on last edited by
          #4

          No problem, mate :)

          Just be careful, styles follow parent-child hierarchy, which can lead to some headaches at times ;)

          (Z(:^

          1 Reply Last reply
          0
          • D Offline
            D Offline
            Dolphin
            wrote on last edited by
            #5

            Derailed now back onto this.

            Got any example files? I took the css code from QtCreator (which was working fine), created a new css file in VS 2010 project, loaded it in the app (setStyleString gets a valid string of css). No styles applied and I cannot seem to find an actual example file just snippets of css (qss to be picky!!)
            @
            body
            {
            /labels/
            QLabel
            {
            color: rgb(255, 255, 0);
            font: 24px;
            background-color:transparent;
            }
            /list views/
            QListView
            {
            background-color:transparent;
            font:24px;
            }
            QListView::item
            {
            color: rgb(255, 255, 0);
            font: 24px;
            border-width:5px;
            border-style: inset;
            padding: 5px;
            margin:5px;
            }
            QListView::item:selected
            {
            border: 10px solid #990066;
            }
            QListView::item:selected:!active
            {
            background: qlineargradient(x1: 0, y1: 0, x2: 0, y2: 1,stop: 0 #ABAFE5, stop: 1 #8588B2);
            }

             QListView::item:selected:active 
            {
              background: qlineargradient(x1: 0, y1: 0, x2: 0, y2: 1, stop: 0 #6a6ea9, stop: 1 #888dd9);
            }
            
            QListView::item:hover 
            {
              background: qlineargradient(x1: 0, y1: 0, x2: 0, y2: 1,stop: 0 #FAFBFE, stop: 1 #DCDEF1);
            }
            /*Buttons*/
            QPushButton
            {
              color:white;
              font:20px;
              border-width: 1px;
              border-color: #339;
              border-style: solid;
            }
            QPushButton:pressed
            {
               border-style: inset;
            }
            

            }
            @

            [Edit: Added @-tags -- mlong]

            1 Reply Last reply
            0
            • sierdzioS Offline
              sierdzioS Offline
              sierdzio
              Moderators
              wrote on last edited by
              #6

              Doh, I have one, but it's proprietary, I cannot distribute it, at least not without going through some bureaucratic arrangements with people above ;)

              I'm not too familiar with QSS, I have used it only occasionally myself. The part "body" seems out of place. What is it for? Try running the code without it. And make sure that the application actually sees the file and reads it properly (you know, somtimes the build automatically places the binary in another folder, and if your paths are relative, it might not find the file).

              (Z(:^

              1 Reply Last reply
              0
              • D Offline
                D Offline
                Dolphin
                wrote on last edited by
                #7

                I originally just placed the code from the creator into the file and that did not work (by debugging I can see the content of the file is being read) so I used Qt tools to create a file and it put that body tag in so I tried that.

                Thanks any way.

                1 Reply Last reply
                0
                • D Offline
                  D Offline
                  Dolphin
                  wrote on last edited by
                  #8

                  Hey, now I am a badger!

                  1 Reply Last reply
                  0
                  • D Offline
                    D Offline
                    Dolphin
                    wrote on last edited by
                    #9

                    File encoding was wrong....... phew!

                    1 Reply Last reply
                    0
                    • sierdzioS Offline
                      sierdzioS Offline
                      sierdzio
                      Moderators
                      wrote on last edited by
                      #10

                      hah :) It's usually some small detail like this. So you are good now?

                      (Z(:^

                      1 Reply Last reply
                      0
                      • D Offline
                        D Offline
                        Dolphin
                        wrote on last edited by
                        #11

                        I'm always a good girl ;-)

                        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