C++ QTableView/QTableWidget 网格样式表 - 网格线宽
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/26162387/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
QTableView/QTableWidget grid stylesheet - grid line width
提问by j123b567
I would like to display table in Qt with specific style. I want to draw all grid lines with same color and same width.
我想在 Qt 中以特定样式显示表格。我想绘制所有具有相同颜色和相同宽度的网格线。
Problem is, that it is hard to style QHeaderView
. All the time, I get 2px grid width or no grid at all.
问题是,很难设计风格QHeaderView
。一直以来,我都会得到 2px 的网格宽度或根本没有网格。
I Have folowing window with one QTableWIdget
我有一个 QTableWIdget 的以下窗口
and asociated styleSheet
和相关的样式表
QWidget {
background-color: #333333;
color: #fffff8;
}
QHeaderView::section {
background-color: #646464;
padding: 4px;
border: 1px solid #fffff8;
font-size: 14pt;
}
QTableWidget {
gridline-color: #fffff8;
font-size: 12pt;
}
QTableWidget QTableCornerButton::section {
background-color: #646464;
border: 1px solid #fffff8;
}
Are there any tricks to have all grid lines 1px width? I'm using 4.8.5 and I can't upgrade to version 5.x.
是否有任何技巧可以使所有网格线宽度为 1px?我使用的是 4.8.5,但无法升级到 5.x 版。
采纳答案by j123b567
The trick is border-style: none;
in QHeaderView::section
after witch border-left
, border-right
, border-top
and border-bottom
starts working. Correct style for QHeaderView::section
should be
诀窍是border-style: none;
在QHeaderView::section
巫后border-left
,border-right
,border-top
并border-bottom
开始工作。正确的风格QHeaderView::section
应该是
QHeaderView::section {
background-color: #646464;
padding: 4px;
font-size: 14pt;
border-style: none;
border-bottom: 1px solid #fffff8;
border-right: 1px solid #fffff8;
}
QHeaderView::section:horizontal
{
border-top: 1px solid #fffff8;
}
QHeaderView::section:vertical
{
border-left: 1px solid #fffff8;
}
回答by pmpod
I think what you did is you added additional border for section cells, and the section properties should look like that ( although I did not try this solution )
我认为您所做的是为部分单元格添加了额外的边框,并且部分属性应如下所示(尽管我没有尝试此解决方案)
QHeaderView::section {
background-color: #646464;
padding: 4px;
border: 0px;
font-size: 14pt;
}
For more information how to style your headers, see:
有关如何设置标题样式的更多信息,请参阅: