How to centralize the QTreeWidget
header?
I have the following 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:
myTableWidget->horizontalHeaderItem(0)->setTextAlignment(Qt::AlignCenter);
But QTreeWidget
doesn't have horizontalHeaderItem().
I'm on Qt 5.3.
I found a solution:
ui->myTreeWidget->header()->setDefaultAlignment(Qt::AlignCenter);
Set the default alignment as centralized to the QHeaderView
.
Documentation: http://doc.qt.io/qt-4.8/qheaderview.html#defaultAlignment-prop