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]Load qss as global.

[Solved]Load qss as global.

Scheduled Pinned Locked Moved General and Desktop
11 Posts 4 Posters 5.2k 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.
  • W Offline
    W Offline
    weblife
    wrote on last edited by
    #1

    Is the below the correct way to load a style sheet globally? I am trying to make things a bit more efficient than:
    @middleIntText -> setStyleSheet("QLineEdit { border: 1px solid gray;border-radius: 5px;padding: 0 8px;selection-background-color:darkgray;height:40px;font-size:15px;}");@

    I thought the following would work at loading QLineEdit the one time for all QLineEdit widgets:
    qss file:
    @QLineEdit { border: 1px solid gray;
    border-radius: 5px;
    padding: 0 8px;
    selection-background-color:darkgray;
    height:40px;
    font-size:15px;}@

    cpp file:
    @QApplication a(argc, argv);
    QFile stylesheet("formStyle.qss");
    stylesheet.open(QFile::ReadOnly);
    QString setSheet = QLatin1String(stylesheet.readAll());
    a.setStyleSheet(setSheet);@

    Perhaps this is right and I am doing something else wrong?

    Brandon Clark
    www.themindspot.com

    1 Reply Last reply
    0
    • L Offline
      L Offline
      lgeyer
      wrote on last edited by
      #2

      It is and you are not.

      1 Reply Last reply
      0
      • W Offline
        W Offline
        weblife
        wrote on last edited by
        #3

        Okay that is good to read, thank you very much. Now I have to find out why its not working. Back to the books! Maybe I will get this figured out by tomorrow... hopeful.

        Brandon Clark
        www.themindspot.com

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

          Don't know if that would help, but you can try setting the style sheet on your topmost widget (usually a QMainWindow) with ::setStyleSheet(). Settings are then propagated down the meta object hierarchy.

          (Z(:^

          1 Reply Last reply
          0
          • W Offline
            W Offline
            weblife
            wrote on last edited by
            #5

            That makes great sense. Need to get some sleep I think cause everything I tried on your suggestion was a no go though. I tried applying in the cardUI class and to QMainWindow and to it in main with cardUI widget.

            Like:
            @QMainWindow::setStyleSheet(setSheet);@
            and
            @cardUI::setStyleSheet(setSheet);@

            Brandon Clark
            www.themindspot.com

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

              You have to set it on an existing object, not a class itself, but you probably know that. Yeah, get some sleep, that usually helps in problem solving :) Your code looks good, I don't know why it's not working. Maybe check your QSS file's encoding (with/ without BOM, etc.)?

              (Z(:^

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

                Ah, one thing. Be sure to check if the QFile::open() was successful (it returns a handy bool for that). Maybe it's just that the file is not where you point to :)

                (Z(:^

                1 Reply Last reply
                0
                • L Offline
                  L Offline
                  leon.anavi
                  wrote on last edited by
                  #8

                  [quote author="weblife" date="1343372467"]That makes great sense. Need to get some sleep I think cause everything I tried on your suggestion was a no go though. I tried applying in the cardUI class and to QMainWindow and to it in main with cardUI widget.
                  [/quote]

                  Applying global stylesheets to QApplication instance is fine but make sure that your qss is correct. Here is a working example source that I had to use recently for my project following the official "Qt Style Sheets examples":http://qt-project.org/doc/qt-4.8/stylesheet-examples.html#customizing-qcheckbox :

                  @
                  QString sCheckBoxStyle = "QCheckBox::indicator { width: 30px; height: 30px; }";
                  sCheckBoxStyle += " QCheckBox::indicator:unchecked { image: url(:/images/checkbox_unchecked.png); }";
                  sCheckBoxStyle += "QCheckBox::indicator:unchecked:hover { image: url(:/images/checkbox_unchecked.png); }";
                  sCheckBoxStyle += "QCheckBox::indicator:unchecked:pressed { image: url(:/images/checkbox_unchecked.png); }";
                  sCheckBoxStyle += " QCheckBox::indicator:checked { image: url(:/images/checkbox_checked.png); }";
                  sCheckBoxStyle += "QCheckBox::indicator:checked:hover { image: url(:/images/checkbox_checked.png); }";
                  sCheckBoxStyle += "QCheckBox::indicator:checked:pressed { image: url(:/images/checkbox_checked.png); }";
                  sCheckBoxStyle += "QCheckBox::indicator:indeterminate:hover { image: url(:/images/checkbox_checked.png); }";
                  sCheckBoxStyle += "QCheckBox::indicator:indeterminate:pressed { image: url(:/images/checkbox_checked.png); }";

                  app->setStyleSheet(sCheckBoxStyle);
                  

                  @

                  http://anavi.org/

                  1 Reply Last reply
                  0
                  • W Offline
                    W Offline
                    weblife
                    wrote on last edited by
                    #9

                    @sierdzio and
                    @leon.anavi

                    You guys are rock stars. Helped me and taught me useful insight, thank you so much. Even though I haven't tried out your suggestions to the fullest I see the answer on the horizon, but now I must sleep.

                    Brandon Clark
                    www.themindspot.com

                    1 Reply Last reply
                    0
                    • W Offline
                      W Offline
                      weblife
                      wrote on last edited by
                      #10

                      It was the target object. Told you I was tired. In my UI class was centralized on QWidget. I also had to point to the correct location.

                      @QWidget::setStyleSheet(setSheet);@

                      Brandon Clark
                      www.themindspot.com

                      1 Reply Last reply
                      0
                      • L Offline
                        L Offline
                        leon.anavi
                        wrote on last edited by
                        #11

                        [quote author="weblife" date="1343398537"]It was the target object. Told you I was tired. In my UI class was centralized on QWidget.

                        @QWidget::setStyleSheet(setSheet);@[/quote]

                        I am happy that you have found and fixed your issue. Well done :)

                        http://anavi.org/

                        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