提问人:Mika 提问时间:8/11/2023 更新时间:8/12/2023 访问量:25
当只有一列存在时,QTableWidget::section:first 不起作用
QTableWidget::section:first doesn't work when only one column exists
问:
我尝试创建一个表头,它将具有简约的设计。
为此,我隐藏了所有边框,除了标题中每个项目的底部边框和左边框。为了避免第一部分左边框与表格边框堆叠,我添加了设置。代码如下:QTableWidget::section:first
QTableWidget::item {
border: none;
padding-left: 5px;
padding-right: 5px;
}
QTableView {
border: 2px solid #CCCCCC;
border-radius: 7px;
color: #3B3B3B;
background: transparent;
selection-background-color: #D3E3ED;
selection-color: #3B3B3B;
margin: 1px;
alternate-background-color: #EBEBEB
}
QHeaderView {
font-family:'Segoe UI';
font-size:12pt bold;
background: #EBEBEB;
border-top-left-radius: 5px;
border-top-right-radius: 5px;
}
QHeaderView::section {
font-weight: bold;
border: none;
background: transparent;
padding: 2px;
padding-left: 7px;
padding-right: 7px;
border-bottom: 1px solid #CCCCCC;
border-left: 1px solid #CCCCCC;
}
QHeaderView::section:first{
border-left: 0px;
}
QTableView::corner {
background-color: transparent;
}
一切都很好,除了表中只有一列的情况(应该是表中的第一列、最后一列和唯一的一列)。然后,它看起来停止工作,并且该部分显示为左边框。section:first
但是,当我添加两列或更多列时,所有列都会再次正常化。
这种行为的根源是什么?
是否可以使用纯 css 修复此行为,而无需在每次列数量更改时在代码中调用 setStyleSheet?
答:
0赞
musicamante
8/12/2023
#1
假设它也是许多部分中的第一个,但你只有一个部分。first
如QHeaderView的QSS参考中所述,子控件也支持伪状态,因此您需要为这两种状态指定规则。:section
only-one
QHeaderView::section:first, QHeaderView::section:only-one {
border-left: 0px;
}
评论