Qtablewidget 表格表头的边框和背景去不掉
时间: 2024-03-05 19:50:51 浏览: 38
您可以使用以下代码来去除QTableWidget表头的边框和背景:
```python
tableWidget.horizontalHeader().setStyleSheet("QHeaderView::section { background-color: transparent; border: 0px solid gray; }")
tableWidget.verticalHeader().setStyleSheet("QHeaderView::section { background-color: transparent; border: 0px solid gray; }")
```
这将会把水平和垂直表头的背景和边框设置为透明,并且没有边框。您可以根据需要自定义样式表。
相关问题
Qtablewidget表格左右拖拽列宽时的,左右拖拽标识样式用qss怎么修改
你可以使用以下样式表来修改左右拖拽标识样式:
```css
QHeaderView::section {
background-color: white;
border: 1px solid #ddd;
padding: 4px;
}
QHeaderView::section::handle {
background-color: #ddd;
border: 1px solid #aaa;
width: 4px;
}
QHeaderView::section::handle:hover {
background-color: #bbb;
border: 1px solid #666;
}
```
在这个样式表中,我们将表头的背景色设置为白色,边框设置为灰色,内边距设置为4个像素。然后,我们使用 `::handle` 伪元素来设置左右拖拽标识的样式,将它的背景色设置为灰色,边框设置为深灰色,宽度设置为4个像素。当鼠标悬停在左右拖拽标识上时,我们将其背景色和边框颜色设置为更深的颜色,以提高可见性。
你可以根据需要修改这些样式。将样式表应用到 QTableWidget 控件上即可。
Qtablewidget 样式
QTableWidget是Qt中的一个表格控件,可以通过QSS样式来设置其外观。以下是一些常用的QTableWidget QSS样式:
1. 设置表格边框和背景颜色:
QTableWidget {
border: 1px solid gray;
background-color: white;
}
2. 设置表头的背景颜色和字体:
QHeaderView::section {
background-color: gray;
color: white;
font-size: 14px;
}
3. 设置表格行的背景颜色和字体:
QTableWidget::item {
background-color: lightgray;
color: black;
font-size: 12px;
}
4. 设置选中行的背景颜色:
QTableWidget::item:selected {
background-color: blue;
color: white;
}
5. 设置表格的边框样式和宽度:
QTableWidget {
border-style: solid;
border-width: 1px;
border-color: gray;
}
6. 设置表格的行高和列宽:
QTableWidget::item {
height: 30px;
width: 100px;
}
以上是一些常用的QTableWidget QSS样式,可以根据需要进行调整和修改。