【发布时间】:2016-11-02 13:16:23
【问题描述】:
我希望 treewidget 标题看起来像是一个标签,所以,我想,我必须让它透明吗?我该怎么做?
我尝试了treeWidget->setStyleSheet("QTreeWidget::header {background-color: transparent}");,但它不起作用。
【问题讨论】:
我希望 treewidget 标题看起来像是一个标签,所以,我想,我必须让它透明吗?我该怎么做?
我尝试了treeWidget->setStyleSheet("QTreeWidget::header {background-color: transparent}");,但它不起作用。
【问题讨论】:
标题不是项目视图的子控件,因此QTreeWidget::header 将不起作用。标题是视图的子小部件。
这意味着您可以使用 QTreeWidget QHeaderView {/*style here*/ }
对于标题视图的背景颜色,您可以查看official Qt example。
在您的情况下,当您将样式表直接设置为视图时,您可以省略父级,因此以下内容将满足您的要求:
treeWidget->setStyleSheet("QHeaderView::section { background-color: transparent; }");
【讨论】:
为了设置标题透明,您必须在小部件样式表中添加以下内容:
QAbstractItemView QHeaderView {
show-decoration-selected: 0;
background: transparent;
}
QAbstractItemView::section QHeaderView::section {
show-decoration-selected: 0;
background: transparent;
}
【讨论】: