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. Can not set style sheet to QTableWidget
Forum Updated to NodeBB v4.3 + New Features

Can not set style sheet to QTableWidget

Scheduled Pinned Locked Moved Solved General and Desktop
8 Posts 2 Posters 4.3k 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
    anh_ph
    wrote on last edited by anh_ph
    #1

    I have a QTableWidget on a QDialog. I set the style sheet to QTableWidget like this

    QTableWidget {
    	background-color:#3d5673;
    	color:white;
    	padding:20;
    	border:none;
    }
    
    QHeaderView::section
    {
    	background-color:#3d5673;
    	color: white;
    	border-style:none;
    	font-family: 'Montserrat', sans-serif;
    }
    
    QScrollBar:vertical {
        border:none;
        background: #3d5673;
        width: 20px;
    }
    
    QScrollBar::handle:vertical {
        background: #00FFFF;
        min-height: 20px;
    	border-radius:10;
    }
    
    QTableWidget::item {
    	border-bottom:1px dashed white;
    	font-family: 'Roboto', sans-serif;
    }
    
    QScrollArea{
    	border:none;
    }
    
    QScrollBar::add-line:vertical {
        border:none;
        background: #3d5673;
        height: 0px;
        subcontrol-position: bottom;
        subcontrol-origin: margin;
    }
    
    QScrollBar::sub-line:vertical {
        border:none;
        background: #3d5673;
        height: 0px;
        subcontrol-position: top;
        subcontrol-origin: margin;
    }
    
    QScrollBar::add-page:vertical {
    	background: #3d5673;
    }
    
    QScrollBar::sub-page:vertical {
    	background: #3d5673;
    }
    
    QTableView::item::selected {
    	border-top: 1px solid #00FFFF;
    	border-bottom: 1px solid #00FFFF;
    	color:white;
    }
    

    It's looking good in the Qt creator design. But when I build the app, It's doesn't work.
    Anyone can help me, please. Thank you!!!
    ![in the Qt creator design](dbc3646d-8b98-4e96-9fd6-2b6ef411acf0-image.png l)

    ![when I build the app](ccb720c4-b0cd-41ad-9ec8-c69ef061c6a2-image.png image url)

    1 Reply Last reply
    0
    • mrjjM mrjj

      @anh_ph
      Hi
      Well if you apply directly to the table widget then it
      cants be some other sheet that ruins the scrollbar styling.

      It could some bug in 5.9.

      Could you try the same in a newer Qt version if possible?

      Also you could test in a clean project with one table widget and the stylesheet to see if that works.

      I cannot reproduce it so and the stylesheet seems fine so I think it's something else.

      A Offline
      A Offline
      anh_ph
      wrote on last edited by anh_ph
      #7

      @mrjj
      Hi, I fixed this bug by set stylesheet for each element of the QTableWidget in the constructor like this. I still don't understand why its can not be set stylesheet directly

      ui->dataTable->horizontalHeader()->setStyleSheet("QHeaderView::section{"
                                                                          "background-color:#3d5673;"
                                                                          "color: white;"
                                                                          "border-style:none;"
                                                                          "font-family: 'Montserrat', sans-serif;}");
      
      ui->dataTable->verticalScrollBar()->setStyleSheet(
                                                              "QScrollBar:vertical {"
                                                                   "border:none;"
                                                                   "background: #3d5673;"
                                                                   "width: 20px;}"
      
                                                               "QScrollBar::handle:vertical {"
                                                                   "background: #00FFFF;"
                                                                   "min-height: 20px;"
                                                                   "border-radius:10;}"
      
                                                               "QScrollBar::add-line:vertical {"
                                                                   "border:none;"
                                                                   "background: #3d5673;"
                                                                   "height: 20px;"
                                                                   "subcontrol-position: bottom;"
                                                                   "subcontrol-origin: margin;}"
      
                                                               "QScrollBar::sub-line:vertical {"
                                                                   "border:none;"
                                                                   "background: #3d5673;"
                                                                   "height: 20px;"
                                                                   "subcontrol-position: top;"
                                                                   "subcontrol-origin: margin;}"
      
                                                               "QScrollBar::add-page:vertical {"
                                                                   "background: #3d5673;}"
      
                                                               "QScrollBar::sub-page:vertical {"
                                                                   "background: #3d5673;}");
      

      Thank you for your help!

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

        Hi
        Can be from other stylesheets if you use more than one.

        If i take your stylesheet and paste to a default project. it does
        work as expected.

        Im using Qt5.15/ win 10

        alt text

        A 1 Reply Last reply
        0
        • mrjjM mrjj

          Hi
          Can be from other stylesheets if you use more than one.

          If i take your stylesheet and paste to a default project. it does
          work as expected.

          Im using Qt5.15/ win 10

          alt text

          A Offline
          A Offline
          anh_ph
          wrote on last edited by
          #3

          @mrjj Hi, thanks for your reply.
          I set the stylesheets directly in the Designer and I do not use any other stylesheets for this QTableWidget.

          mrjjM 1 Reply Last reply
          0
          • A anh_ph

            @mrjj Hi, thanks for your reply.
            I set the stylesheets directly in the Designer and I do not use any other stylesheets for this QTableWidget.

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

            @anh_ph
            Hi
            I also set directly in designer. On the tablewidget.

            But do you use a style sheet on the form or other widgets?
            Like on table Widget parent.

            What Qt version are you using ?

            A 1 Reply Last reply
            0
            • mrjjM mrjj

              @anh_ph
              Hi
              I also set directly in designer. On the tablewidget.

              But do you use a style sheet on the form or other widgets?
              Like on table Widget parent.

              What Qt version are you using ?

              A Offline
              A Offline
              anh_ph
              wrote on last edited by anh_ph
              #5

              @mrjj
              Hi,
              Yes, I apply the same stylesheet for the other table on the visiable Widget (not the parent of my dialog). But if so, how can I apply this stylesheet for this table of this dialog?
              I also try to remove all the stylesheet, and set it in the constructor of all the classes which apply this stylesheet, but it didn't work too.
              I'm using Qt 5.9.6/Win 10.

              mrjjM 1 Reply Last reply
              0
              • A anh_ph

                @mrjj
                Hi,
                Yes, I apply the same stylesheet for the other table on the visiable Widget (not the parent of my dialog). But if so, how can I apply this stylesheet for this table of this dialog?
                I also try to remove all the stylesheet, and set it in the constructor of all the classes which apply this stylesheet, but it didn't work too.
                I'm using Qt 5.9.6/Win 10.

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

                @anh_ph
                Hi
                Well if you apply directly to the table widget then it
                cants be some other sheet that ruins the scrollbar styling.

                It could some bug in 5.9.

                Could you try the same in a newer Qt version if possible?

                Also you could test in a clean project with one table widget and the stylesheet to see if that works.

                I cannot reproduce it so and the stylesheet seems fine so I think it's something else.

                A 1 Reply Last reply
                0
                • mrjjM mrjj

                  @anh_ph
                  Hi
                  Well if you apply directly to the table widget then it
                  cants be some other sheet that ruins the scrollbar styling.

                  It could some bug in 5.9.

                  Could you try the same in a newer Qt version if possible?

                  Also you could test in a clean project with one table widget and the stylesheet to see if that works.

                  I cannot reproduce it so and the stylesheet seems fine so I think it's something else.

                  A Offline
                  A Offline
                  anh_ph
                  wrote on last edited by anh_ph
                  #7

                  @mrjj
                  Hi, I fixed this bug by set stylesheet for each element of the QTableWidget in the constructor like this. I still don't understand why its can not be set stylesheet directly

                  ui->dataTable->horizontalHeader()->setStyleSheet("QHeaderView::section{"
                                                                                      "background-color:#3d5673;"
                                                                                      "color: white;"
                                                                                      "border-style:none;"
                                                                                      "font-family: 'Montserrat', sans-serif;}");
                  
                  ui->dataTable->verticalScrollBar()->setStyleSheet(
                                                                          "QScrollBar:vertical {"
                                                                               "border:none;"
                                                                               "background: #3d5673;"
                                                                               "width: 20px;}"
                  
                                                                           "QScrollBar::handle:vertical {"
                                                                               "background: #00FFFF;"
                                                                               "min-height: 20px;"
                                                                               "border-radius:10;}"
                  
                                                                           "QScrollBar::add-line:vertical {"
                                                                               "border:none;"
                                                                               "background: #3d5673;"
                                                                               "height: 20px;"
                                                                               "subcontrol-position: bottom;"
                                                                               "subcontrol-origin: margin;}"
                  
                                                                           "QScrollBar::sub-line:vertical {"
                                                                               "border:none;"
                                                                               "background: #3d5673;"
                                                                               "height: 20px;"
                                                                               "subcontrol-position: top;"
                                                                               "subcontrol-origin: margin;}"
                  
                                                                           "QScrollBar::add-page:vertical {"
                                                                               "background: #3d5673;}"
                  
                                                                           "QScrollBar::sub-page:vertical {"
                                                                               "background: #3d5673;}");
                  

                  Thank you for your help!

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

                    Hi
                    Ok. it should be the same but clearly, it's not.
                    But good it fixes it.

                    1 Reply Last reply
                    1

                    • Login

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