[英]How to centralize the QTreeWidget header
How to centralize the QTreeWidget
header? 如何集中QTreeWidget
标头?
I have the following QTreeWidget
: 我有以下QTreeWidget
:
And I want to centralize the header to look like this: 我想集中头看起来像这样:
I already tried to set this stylesheet: 我已经尝试设置此样式表:
QHeaderView::section {
text-align: center;
}
But it didn't work. 但这没有用。
I know that with QTableWidget
we can do something like this: 我知道,使用QTableWidget
可以执行以下操作:
myTableWidget->horizontalHeaderItem(0)->setTextAlignment(Qt::AlignCenter);
But QTreeWidget
doesn't have horizontalHeaderItem(). 但是QTreeWidget
没有horizontalHeaderItem()。
I'm on Qt 5.3. 我使用的是Qt 5.3。
I found a solution: 我找到了解决方案:
ui->myTreeWidget->header()->setDefaultAlignment(Qt::AlignCenter);
Set the default alignment as centralized to the QHeaderView
. 将默认对齐方式设置为集中到QHeaderView
。
Documentation: http://doc.qt.io/qt-4.8/qheaderview.html#defaultAlignment-prop 文档: http : //doc.qt.io/qt-4.8/qheaderview.html#defaultAlignment-prop
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.