I tried the CSS code:
QTableView QHeaderView::section {
text-align: center;
}
And it did not help me.
PS I write the SCADA system in the WinCC OA that uses Qt, and there you can change the appearance of components only using CSS
I tried the CSS code:
QTableView QHeaderView::section {
text-align: center;
}
And it did not help me.
PS I write the SCADA system in the WinCC OA that uses Qt, and there you can change the appearance of components only using CSS
As seen in the source code for QHeaderView::paintSection
QVariant textAlignment = d->model->headerData(logicalIndex, d->orientation,
Qt::TextAlignmentRole);
opt.rect = rect;
opt.section = logicalIndex;
opt.state |= state;
opt.textAlignment = Qt::Alignment(textAlignment.isValid()
? Qt::Alignment(textAlignment.toInt())
: d->defaultAlignment);
QHeaderView
does not uses the stylesheet to define the text alignment, only values from the defaultAlignment
or the data from the header's model (Qt::TextAlignmentRole
).
Now, if your default alignment is either Qt::AlignLeft
or Qt::AlignRight
, you can use the section padding to automatically center it:
QTableView QHeaderView::section {
padding-left: auto;
padding-right: auto;
}
The opposite is not true: if default alignment is center, other calculus affect how padding is used and cannot be used to automatically left- or right-align text.
I have found one of the solutions:
QHeaderView {
qproperty-defaultAlignment: AlignHCenter AlignVCenter;
}
Although it works in WinCC OA only partially.
© 2022 - 2024 — McMap. All rights reserved.