【问题标题】:Qt stylesheets: QHeaderView draws header text in bold when view data is selectedQt stylesheets: QHeaderView draws header text in bold when view data is selected
【发布时间】:2010-12-02 00:33:40
【问题描述】:

我正在尝试使用 Qt 样式表设置 QTableView 的样式。一切正常,除了在选择表格视图中的数据时所有表格标题文本(列标题)都被绘制为粗体文本。

我尝试过这样的事情:

QTableView::section {
    font-weight: 400;
}
QTableView::section:selected {
    font-weight: 400;
}

QHeaderView {
    font-weight: 400;
}

QHeaderView::section {
    font-weight: 400;
}

无济于事。

谁能指出我正确的方向,最好使用样式表?

【问题讨论】:

    标签: c++ qt stylesheet


    【解决方案1】:

    我还没有测试过,但是将 QHeaderView::highlightSections 属性设置为 false 应该可以解决问题。

    您可以使用 QTableView 的 verticalHeader() 和 horizontalHeader() 方法获取指向 QHeaderView 对象的指针。

    【讨论】:

    • 太棒了!我怎么没看到!?谢谢!有趣的是,根据文档,该属性的默认值应该是 false...
    【解决方案2】:

    在 Qt Designer UI 格式中你可以使用属性horizontalHeaderHighlightSections:

     <widget class="QTableView" name="m_studyList">
      <attribute name="horizontalHeaderHighlightSections">
       <bool>false</bool>
      </attribute>
    

    但它也完全禁用选定列的 css。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2013-05-08
      • 1970-01-01
      • 1970-01-01
      • 2020-04-22
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多