Unsolved Set alignment for QTreeView cells
-
Re: Set alignment for QTreeView cells
QTreeView Cell Alignment
QStandardItem:: setTextAlignment(Qt::Alignment)
so
my_model ->item(row, column)->setTextAlignment(Qt::AlignCenter);
Please suggest me if there is another way.
-
@LeeHyunKyu
Why do you want another way? -
@Denni-0
I don't know if that is a question. The way Qt works is that alignments etc. are on a cell-by-cell basis, not a complete row/column. That's just how it is. However, using Qtdata()
way of doing things, among the roles (https://doc.qt.io/qt-5/qt.html#ItemDataRole-enum) there is e.g.Qt::TextAlignmentRole
, so one can write code to affect all cells in a row/column via that return result instead of actually setting alignment on individual cells. -
@Denni-0 said in Set alignment for QTreeView cells:
but I know you can affect an entire column and/or row within a QTreeView as I have done it but cannot find it now
You would look at
index.row()
orindex.column()
to affect row/column:def data(self, index, role): if (role == QtCore.Qt.TextAlignmentRole): if index.row() == whatever or index.column() == something: return QtCore.Qt.AlignHCenter
-
Hi,
You can use a QIdentityProxyModel between your orignal data and your view. You can alter there just what you want.