【问题标题】:How do I make qtreewidget header transparent?如何使 qtreewidget 标头透明?
【发布时间】:2016-11-02 13:16:23
【问题描述】:

我希望 treewidget 标题看起来像是一个标签,所以,我想,我必须让它透明吗?我该怎么做?

我尝试了treeWidget->setStyleSheet("QTreeWidget::header {background-color: transparent}");,但它不起作用。

【问题讨论】:

    标签: qt qt4


    【解决方案1】:

    标题不是项目视图的子控件,因此QTreeWidget::header 将不起作用。标题是视图的子小部件。 这意味着您可以使用 QTreeWidget QHeaderView {/*style here*/ }

    通过样式表访问标题

    对于标题视图的背景颜色,您可以查看official Qt example

    在您的情况下,当您将样式表直接设置为视图时,您可以省略父级,因此以下内容将满足您的要求:

    treeWidget->setStyleSheet("QHeaderView::section { background-color: transparent; }");
    

    【讨论】:

      【解决方案2】:

      为了设置标题透明,您必须在小部件样式表中添加以下内容:

      QAbstractItemView QHeaderView {
          show-decoration-selected: 0;
          background: transparent;
      }
      QAbstractItemView::section QHeaderView::section {
          show-decoration-selected: 0;
          background: transparent;
      }
      

      【讨论】:

        猜你喜欢
        • 2019-03-05
        • 2017-07-04
        • 1970-01-01
        • 2011-07-23
        • 1970-01-01
        • 2018-12-30
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多