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. Qt Gui Application background color stylesheet
Forum Updated to NodeBB v4.3 + New Features

Qt Gui Application background color stylesheet

Scheduled Pinned Locked Moved General and Desktop
10 Posts 4 Posters 13.9k 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.
  • A Offline
    A Offline
    AcidLys
    wrote on last edited by
    #1

    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
    0
    • M Offline
      M Offline
      messi
      wrote on last edited by
      #2

      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
      0
      • S Offline
        S Offline
        Sam
        wrote on last edited by
        #3

        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
        0
        • S Offline
          S Offline
          SherifOmran
          wrote on last edited by
          #4

          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
          0
          • M Offline
            M Offline
            messi
            wrote on last edited by
            #5

            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
            0
            • S Offline
              S Offline
              Sam
              wrote on last edited by
              #6

              [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
              0
              • M Offline
                M Offline
                messi
                wrote on last edited by
                #7

                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
                0
                • S Offline
                  S Offline
                  SherifOmran
                  wrote on last edited by
                  #8

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

                  1 Reply Last reply
                  0
                  • S Offline
                    S Offline
                    SherifOmran
                    wrote on last edited by
                    #9

                    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
                    0
                    • M Offline
                      M Offline
                      messi
                      wrote on last edited by
                      #10

                      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
                      0

                      • Login

                      • Login or register to search.
                      • First post
                        Last post
                      0
                      • Categories
                      • Recent
                      • Tags
                      • Popular
                      • Users
                      • Groups
                      • Search
                      • Get Qt Extensions
                      • Unsolved