You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

QTableWidget暗黑模式下顶部白色块无法消除,如何修复?

QTableWidget暗黑模式顶部白色区域问题解决

问题说明

为应用配置暗黑模式QSS后,QTableWidget的顶部左上角区域始终显示白色,无法匹配暗黑样式。

QTableWidget顶部白色区域

当前使用的QSS代码:

QTableWidget {
        background-color: rgba(29, 29, 29, 250);
         color: rgba(193, 193, 193, 250);
   gridline-color: rgba(0, 0, 0, 0);
}

QTableWidget::item {
         padding: 4px;
}

QTableWidget::item:selected {
         background-color: rgba(50, 50, 50, 250);
}

QTableWidget::item:focus {
         background-color: rgba(70, 70, 70, 250);
         outline: none;
}

QHeaderView::section {
        background-color: rgba(50, 50, 50, 250);
        color: rgba(193, 193, 193, 250);
        padding: 4px;
        border: none;
}

QHeaderView {
        background-color: rgba(50, 50, 50, 250);
        color: rgba(193, 193, 193, 250);
        padding: 4px;
        border: none;
}

QHeaderView::section:checked {
        background-color: rgba(70, 70, 70, 250);
}

解决步骤

  • 白色区域是QTableWidget的角控件(QTableCornerButton),默认不继承父控件样式,需单独添加QSS:
QTableWidget QTableCornerButton::section {
    background-color: rgba(50, 50, 50, 250);
    border: none;
}
  • 如果不需要角控件,也可以通过代码直接隐藏:
// 替换为你的QTableWidget对象名
tableWidget->setCornerButtonEnabled(false);

添加样式后,角控件会匹配QHeaderView的背景色,实现整体暗黑样式统一。


内容的提问来源于stack exchange,提问作者user21815993

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.19 14:27:41