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. [RESOLVED] StyleSheet file... it's possible?
Forum Updated to NodeBB v4.3 + New Features

[RESOLVED] StyleSheet file... it's possible?

Scheduled Pinned Locked Moved General and Desktop
12 Posts 3 Posters 8.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.
  • D Offline
    D Offline
    dcbasso
    wrote on last edited by
    #1

    Hi guys, I'm again...
    Well, I'm trying to decorate my application with CSS.
    I want to set a style for all buttons, for every element of my application, but I was thinking to use a file "mystyle.css" for example to put all CSS codes inside read this file and set this styles on my application... This is possible?

    I'm reading the docs and at least I don't found nothing about this... I will keep reading...

    Thanks all...

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

      Yes. Load the file (perhaps from a resource) at application startup into a QString, and then call setStyleSheet on your QApplication instance.

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

        Thanks Andre!

        1 Reply Last reply
        0
        • B Offline
          B Offline
          broadpeak
          wrote on last edited by
          #4

          @
          QFile fileDark(":/qss/vc2.qss");
          fileDark.open(QFile::ReadOnly);
          app.setStyleSheet(fileDark.readAll());
          @

          qss is a css file, it is embedded as qresource

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

            [quote author="broadpeak" date="1347370429"]@
            ...[/quote]
            You're spoiling all the "this is left as an excersise for the reader" fun! ;-)

            1 Reply Last reply
            0
            • D Offline
              D Offline
              dcbasso
              wrote on last edited by
              #6

              Thanks broadpeak.
              I'm already using here, with .css and qresource. Works very well.

              Thanks.

              1 Reply Last reply
              0
              • B Offline
                B Offline
                broadpeak
                wrote on last edited by
                #7

                [quote author="Andre" date="1347370510"][quote author="broadpeak" date="1347370429"]@
                ...[/quote]
                You're spoiling all the "this is left as an excersise for the reader" fun! ;-)

                [/quote]

                Ahhhhhhhhhh! Sorry :) I will never.... :)

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

                  By the way: note that your (broadpeak) method has a potential danger. You implicitly cast a QByteArray to a QString: QFile::readAll() returns a QByteArray, while setStyleSheet takes a QString. That means that you assume that the .css file will be ASCII (see the docs for QString). That might or might not be a valid assumption... I prefer to use a [[doc:QTextStream]] to read a text file instead.

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

                    I use to read some files like the "broadpeak" code!
                    Nothing wrong at all, but I will read about the QTextStream!

                    Thanks Andre.

                    1 Reply Last reply
                    0
                    • B Offline
                      B Offline
                      broadpeak
                      wrote on last edited by
                      #10

                      [quote author="Andre" date="1347371510"]...that you assume that the .css file will be ASCII ... That might or might not be a valid assumption... I prefer to use a [[doc:QTextStream]] to read a text file instead.
                      [/quote]

                      Yes, of course, you are right (as usual :))!
                      But I always use simple ASCII editor for css editing, because I never have special character in my qss file.

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

                        Well, for instance, the file names for images or object names for widgets may contain unicode characters, especially for developers from non-English speaking countries...

                        1 Reply Last reply
                        0
                        • D Offline
                          D Offline
                          dcbasso
                          wrote on last edited by
                          #12

                          Well, I'm from Brazil and here we use the special chars (çãáâü....) but in source codes and etc... we avoid them... or I void this chars.

                          But for safe reasons appears to me better use the "QTextStream".

                          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