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. Custom Stylesheeting and custom painting

Custom Stylesheeting and custom painting

Scheduled Pinned Locked Moved General and Desktop
9 Posts 4 Posters 4.9k 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.
  • R Offline
    R Offline
    ronM71
    wrote on last edited by
    #1

    My application uses an external stylesheet for skinning. There is a default *.qss file that's compiled with the app's resources, and users should be able to replace it with their own.

    In my app, I have a QListView that I custom draw with my own item delegate. I'd like to provide for an "odd/even" item row background. I'd like the colors of these backgrounds to be determined in the *.QSS file.

    any ideas if this is at all possible? It's like I need access to custom fields in my QSS file from my paint method on my item delegate. Of course, I can open that file and analyze its contents myself, but i'd much rather use a systemic approach to this, if one exists of course.

    1 Reply Last reply
    0
    • A Offline
      A Offline
      andre
      wrote on last edited by
      #2

      There is no Qt API to do this, unfortunately. The whole stylesheet based styling is a bit of a blackbox, and can not be combined with custom painting easily. There is no public API for accessing the evaluated results of a style sheet for an item that needs to be drawn. I fear that analyzing the contents of the file yourself (or, perhaps easier, setting these values separately if you don't want to have to write a complete CSS parser) is your only way out.

      1 Reply Last reply
      0
      • P Offline
        P Offline
        paucoma
        wrote on last edited by
        #3

        Hi,
        I'm pretty much a newbie still but have been spending a lot of time looking at examples and remembered this one: "Style Sheet Example":http://doc.qt.nokia.com/latest/widgets-stylesheet.html
        Maybe it could give you some ideas.

        In one of the style sheets: coffee.qss
        They specify the bq. “odd/even” item row background
        @QTreeView {
        alternate-background-color: yellow;
        }@

        1 Reply Last reply
        0
        • R Offline
          R Offline
          ronM71
          wrote on last edited by
          #4

          Thanks. I do want it to be part of my CSS. I'll write a simple parser that just looks for the name of the QListView it's called for (e.g. "QListView#<myObjectName>" and parse the values below to fish for the odd/even background values.

          There is no need to open the file itself I think, since I set the stylesheet to the QApplication, I believe I can get it as a string, and just parse the string. Will check.

          1 Reply Last reply
          0
          • R Offline
            R Offline
            ronM71
            wrote on last edited by
            #5

            Hi Paucoma, this is custom drawing using an item delegate so in any case, I need to look for those properties and apply them myself.

            1 Reply Last reply
            0
            • A Offline
              A Offline
              andre
              wrote on last edited by
              #6

              Fine, if it works for you...
              Just realize that if your user is allowed to modify the CSS used, he might use other selectors. He might not use the name of your list view for instance, but want to apply the style, or only this part, to all list views in the application. Then your custom parsing would fail, and your users might (rightly) start to complain about a bug. The solution is a bit fragile, it seems. But if you are happy with it, then that is obviously the most important thing :-)

              1 Reply Last reply
              0
              • R Offline
                R Offline
                ronM71
                wrote on last edited by
                #7

                I believe I misled you, by "user" I meant our own marketing/sales who will re-brand our software as needed. I'm not talking about the end user.

                1 Reply Last reply
                0
                • A Offline
                  A Offline
                  andre
                  wrote on last edited by
                  #8

                  [quote author="ronM71" date="1300810954"]I believe I misled you, by "user" I meant our own marketing/sales who will re-brand our software as needed. I'm not talking about the end user.[/quote]
                  Ah, ok. In that case, I guess it is a question of properly documenting this, so you, your successor and the marketing department will not be surprised by this issue :-)

                  1 Reply Last reply
                  0
                  • G Offline
                    G Offline
                    giesbert
                    wrote on last edited by
                    #9

                    If you use the "QStyledItemDelegate":http://doc.qt.nokia.com/4.7/QStyledItemDelegate.html you get colors set by the stylesheet in the paint event. And if you call the default methods, the style sheet drawing is used.

                    I'm using this for changing some smaller things in painting...

                    Nokia Certified Qt Specialist.
                    Programming Is Like Sex: One mistake and you have to support it for the rest of your life. (Michael Sinz)

                    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