Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved

    Update: Forum Guidelines & Code of Conduct

    Qt Gui Application background color stylesheet

    General and Desktop
    4
    10
    13464
    Loading More Posts
    • 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.
    • A
      AcidLys last edited by

      I want to set background color for my form

      like this
      @
      body
      {
      background-color: #fff;
      }@
      I am using QWidget selector but i only want to change window background;

      And how i can ise one stylesheet for all windows?

      1 Reply Last reply Reply Quote 0
      • M
        messi last edited by

        Hi AcidLys,

        have you read this link. It is very useful. It explains how to use stylesheet.

        http://qt-project.org/doc/qt-4.8/stylesheet-syntax.html

        If you like to use a stylesheet file for the whole app, then you have to load it in your main.cpp.

        Checkout QApplication::setStylesheet();

        1 Reply Last reply Reply Quote 0
        • S
          Sam last edited by

          For more information on StyleSheets you can check

          "Qt Style Sheets Reference":http://qt-project.org/doc/qt-4.8/stylesheet-reference.html#list-of-properties

          "Qt Style Sheets Examples":http://doc-snapshot.qt-project.org/4.8/stylesheet-examples.html

          also in order to set the stylesheet for the whole application you can try the following code:

          @QFile styleSheet(":/Stylesheet/yourStylesheet.qss"); //path where the file is stored
          if (!styleSheet.open(QIODevice::ReadOnly)
          {
          qWarning("Unable to open ::/Stylesheet/yourStylesheet.qss");
          return;
          }
          qApp->setStyleSheet(styleSheet.readAll());@

          1 Reply Last reply Reply Quote 0
          • S
            SherifOmran last edited by

            This does not help in case of message box or a custom widget which i don't know how to be done. I searched the internet before i ask. In case you know, please reply, otherwise no problem.

            1 Reply Last reply Reply Quote 0
            • M
              messi last edited by

              Hi SherifOmran,
              do you try to hitchhike this tread?
              In the first mail messageBox was not mentioned and it was send by another author.

              Here, is what you are looking for, I got it from the qt documentations:

              @*[environment="##ENV"] QMessageBox{
              background-color: ##INACTIVE;
              border: 3px solid ##EXTRA_DARK;
              }

              *[environment="##ENV"] QMessageBox QPushButton{
              border-radius: 8px;
              icon-size: 28px;
              min-height: 42px;
              max-height: 42px;
              min-width: 50px;
              background: qlineargradient(x1:0, y1:0, x2:0, y2:1, stop:0 ##NORMAL, stop: 0.1 ##INACTIVE, stop:0.15 ##NORMAL, stop:0.9 ##NORMAL, stop:1 ##EXTRA_DARK);
              border: 0px solid none;
              border-right: 2px solid ##NORMAL;
              border-left: 2px solid ##NORMAL;
              }

              *[environment="##ENV"] QMessageBox QPushButton:pressed,
              *[environment="##ENV"] QMessageBox QPushButton:checked{
              background: qlineargradient(x1:0, y1:0, x2:0, y2:1, stop:0 ##EXTRA_DARK, stop: 0.1 ##PRESSED, stop:0.8 ##PRESSED, stop:0.9 ##NORMAL, stop:1 ##PRESSED);
              border: 2px solid ##PRESSED;
              }@

              1 Reply Last reply Reply Quote 0
              • S
                Sam last edited by

                [quote author="messi" date="1346654781"]Hi SherifOmran,
                do you try to hitchhike this tread?
                In the first mail messageBox was not mentioned and it was send by another author.

                [/quote]

                The actual discussion for the message box was going "on this thread":http://qt-project.org/forums/viewthread/20041/ so for the implementation I directed him here, not his fault :)

                Thanks for the code messi :)

                1 Reply Last reply Reply Quote 0
                • M
                  messi last edited by

                  Ok.
                  Anyway, almost every widget/dialog is styleable. Always a good approach is to checkout the qt sourcecode directly.

                  In my code you have to replace the ##...... with your own color. Also the conditional clause in the square brackets are optional.

                  1 Reply Last reply Reply Quote 0
                  • S
                    SherifOmran last edited by

                    Oh, I am sorry, did nt realize it is another thread.

                    1 Reply Last reply Reply Quote 0
                    • S
                      SherifOmran last edited by

                      If I am allowed to ask. What does *[environment="##ENV"] mean? and what should I put instead of #ENV?

                      I don't find it in the documentation. Any link?

                      1 Reply Last reply Reply Quote 0
                      • M
                        messi last edited by

                        The code is quite complicated and it would need a long explanation.
                        Remove all *[environment="##ENV"] and replace all words with ## with color value.

                        For more info please checkout the following links.

                        http://qt-project.org/doc/qt-4.8/stylesheet-syntax.html
                        http://qt-project.org/doc/qt-4.8/stylesheet-customizing.html

                        1 Reply Last reply Reply Quote 0
                        • First post
                          Last post