QTableWidget滑块的样式表怎么设置
时间: 2024-06-13 19:07:57 浏览: 163
“Qt”+“C++”+QTableWidget控件自定义表头,合并,重写样式
以下是设置QTableWidget滑块样式表的方法:
```python
# 设置QTableWidget滑块样式表
self.tableWidget.verticalScrollBar().setStyleSheet("QScrollBar:vertical{background:#FFFFFF;border:none;width:10px;margin:0px 0px 0px 0px;}"
"QScrollBar::handle:vertical{background:#E6E6E6;border-radius:5px;width:10px;margin:0px 0px 0px 0px;}"
"QScrollBar::handle:vertical:hover{background:#CFCFCF;border-radius:5px;width:10px;margin:0px 0px 0px 0px;}"
"QScrollBar::add-line:vertical{background:url(:/images/down.png) center no-repeat;width:10px;height:10px;subcontrol-position:bottom;}"
"QScrollBar::sub-line:vertical{background:url(:/images/up.png) center no-repeat;width:10px;height:10px;subcontrol-position:top;}"
"QScrollBar::add-line:vertical:hover{background:url(:/images/down_hover.png) center no-repeat;width:10px;height:10px;subcontrol-position:bottom;}"
"QScrollBar::sub-line:vertical:hover{background:url(:/images/up_hover.png) center no-repeat;width:10px;height:10px;subcontrol-position:top;}"
"QScrollBar::add-page:vertical,QScrollBar::sub-page:vertical{background:none;}")
```
其中,`self.tableWidget`是QTableWidget对象的名称,`verticalScrollBar()`是获取QTableWidget的垂直滑块的方法,`setStyleSheet()`是设置样式表的方法。在样式表中,`QScrollBar:vertical`表示垂直滑块,`QScrollBar::handle:vertical`表示滑块的手柄,`QScrollBar::add-line:vertical`和`QScrollBar::sub-line:vertical`表示滑块的上下箭头,`QScrollBar::add-page:vertical`和`QScrollBar::sub-page:vertical`表示滑块的背景。
阅读全文