简体   繁体   English

如何集中QTreeWidget标头

[英]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没有horizo​​ntalHeaderItem()。

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM