View Full Version : How to right-justify text line inside a QTreeView

24th September 2014, 01:32
I have a QTreeView with cells (on the same column) each having very long texts. I want to display only the most right characters of the text since each text represents a very long file name.

How to right justify the texts of the column of a QTreeView?

24th September 2014, 04:23
If you are using QTreeView, then you are using a QAbstractItemModel (or a class derived from it), right?

Implement the Qt::TextAlignmentRole for the QAbstractItemModel::data() method, and have it return Qt::AlignRight | Qt::AlignVCenter.

Alternatively, if elided text is OK for you, then you could call QAbstractItemView::setTextElideMode() with the value Qt::ElideLeft. That will give you something that looks like "... very long file name" (but not the ability to scroll the text to the beginning).