Can not set style sheet to QTableWidget
-
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]( l)![when I build the app]( image url)
-
@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 directlyui->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!
-
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
-
@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. -
@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.
-
@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 directlyui->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!
-
Hi
Ok. it should be the same but clearly, it's not.
But good it fixes it.