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. stylsheet is not working in main widget
Forum Updated to NodeBB v4.3 + New Features

stylsheet is not working in main widget

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

    qt 5.11.1 , linux.
    i applied this stylesheet in the main widget .

    QWidget {
    background-color: #1C2836;
    color: #ffffff;
    }
    

    the widget shows fine in designer.

    0_1530414137386_b3.png

    after build i am seeing it is only applied in the label ,buttons not in the main widgets backgrounds and SPACING .
    0_1530414179648_b2.png

    when add another widget in the main widget and apply stylesheet on that secind widget it works fine. like this

    0_1530414318544_b1.png

    1 Reply Last reply
    0
    • N Offline
      N Offline
      nkiy
      wrote on last edited by
      #2

      Like in List of Stylable Widgets said, QWidget only supports 3 style properties: background, background-clip, background-origin.
      You might using QPalette:

      m_myWidget = new QWidget(this);
      m_myWidget->setGeometry(0, 0, 300, 100);
      QPalette pal = palette();
      
      // set black background
      pal.setColor(QPalette::Background, Qt::black);
      m_myWidget->setAutoFillBackground(true);
      m_myWidget->setPalette(pal);
      m_myWidget->show();
      
      

      from: https://wiki.qt.io/How_to_Change_the_Background_Color_of_QWidget

      S 1 Reply Last reply
      1
      • N nkiy

        Like in List of Stylable Widgets said, QWidget only supports 3 style properties: background, background-clip, background-origin.
        You might using QPalette:

        m_myWidget = new QWidget(this);
        m_myWidget->setGeometry(0, 0, 300, 100);
        QPalette pal = palette();
        
        // set black background
        pal.setColor(QPalette::Background, Qt::black);
        m_myWidget->setAutoFillBackground(true);
        m_myWidget->setPalette(pal);
        m_myWidget->show();
        
        

        from: https://wiki.qt.io/How_to_Change_the_Background_Color_of_QWidget

        S Offline
        S Offline
        saber
        wrote on last edited by
        #3

        @nkiy

        i am not using QPalette . if i wanted to use qpalette i have do alot of work.

        i was using stylsheet for each widgets and it works fine then .but i want to set one stylesheet in main widget so it is a better and perfect way.
        but it is giving me this.

        1 Reply Last reply
        0
        • mrjjM Offline
          mrjjM Offline
          mrjj
          Lifetime Qt Champion
          wrote on last edited by mrjj
          #4

          Hi
          Try to set
          setAutoFillBackground(true); for Wbattery
          (its a property so you can do in Designer)
          Also, did you set the layouts margins to zero- so there is no spaces ?
          alt text

          I think what you are seeing is once you use wBattery in app,
          it get more space, so layout spaces the items. Widgets have
          no background pr default so you look through and see the other window under it.

          Depending on what you need, you might also want to set its maximumsize so it stays like in Designer. Else when you insert in some other widget, it might be bigger if more space for it.
          alt text
          Only do this if goal is to stay same size even when mainwindow resizes.

          S 1 Reply Last reply
          1
          • mrjjM mrjj

            Hi
            Try to set
            setAutoFillBackground(true); for Wbattery
            (its a property so you can do in Designer)
            Also, did you set the layouts margins to zero- so there is no spaces ?
            alt text

            I think what you are seeing is once you use wBattery in app,
            it get more space, so layout spaces the items. Widgets have
            no background pr default so you look through and see the other window under it.

            Depending on what you need, you might also want to set its maximumsize so it stays like in Designer. Else when you insert in some other widget, it might be bigger if more space for it.
            alt text
            Only do this if goal is to stay same size even when mainwindow resizes.

            S Offline
            S Offline
            saber
            wrote on last edited by
            #5

            @mrjj

            i need those spaces for looks. so i gess i have to add padding in qstylesheet to get those spaces.

            thanks.

            mrjjM 1 Reply Last reply
            0
            • S saber

              @mrjj

              i need those spaces for looks. so i gess i have to add padding in qstylesheet to get those spaces.

              thanks.

              mrjjM Offline
              mrjjM Offline
              mrjj
              Lifetime Qt Champion
              wrote on last edited by
              #6

              @saber
              Well the margins for layout works just as well.
              so maybe just setAutoFillBackground look like you want.

              S 1 Reply Last reply
              0
              • mrjjM mrjj

                @saber
                Well the margins for layout works just as well.
                so maybe just setAutoFillBackground look like you want.

                S Offline
                S Offline
                saber
                wrote on last edited by
                #7

                @mrjj
                any solution for this post
                stylsheet is not working properly

                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