如何设置QTreeWidget标题颜色并隐藏分界线?

问题描述 投票:0回答:3

我想在使用QWidget时更改标题的背景颜色。我尝试了以下方法,但它们不起作用:

QTreeWidgetItem * header = ui->treeWidget->headerItem(); 
header->setBackground(0, QBrush(QColor(185,192,201)));
header->setBackgroundColor(0, QColor(185,192,201));

setStyleSheet("QHeaderView::section { background-color:red }");

我也想知道如何隐藏标题的分界线?

c++ css qt qwidget
3个回答
0
投票

你为什么不只使用样式表?

YourQTreeWidget QHeaderView::section {
    background-color: red; // for the bakcground
    border-right: none; // right-border of each section
    border-left: none;  // left border of each section
}

0
投票

正如你可以阅读here(正如你在你的例子中看到的)setBackgroundColor不适用于标题项(我怀疑这是由于标题和行项之间的差异)。你应该重新实现QHeaderView或尝试上述选项。


0
投票

我找到了一种方法来改变标题的样式,但我不知道为什么我以前的方法不起作用。

QHeaderView::section {                          
    color: black;                               
    padding: 2px;                               
    height:20px;                                
    border: 0px solid #567dbc;                  
    border-left:0px;                            
    border-right:0px;                           
    background: #f9f9f9;                        
}
© www.soinside.com 2019 - 2024. All rights reserved.