Suppose I have a QTableWidget. Then, I create items for it
QString pathname="C:\\Directory1\\Directory2\\Directory3\\example.txt";
QTableWidgetItem*item=new QTableWidgetItem(pathname);
item->setTextAlignment(Qt::AlignVCenter | Qt::AlignRight);
ui->myTable->setItem(row, 1, item);
If the column is more narrow than the pathname, then I get something like:
"C:\Directory1\Dir ..."
However, the column display would be much more useful, IMHO, if it were truly right-aligned, in that the end part of the pathname were to be aligned with the right part of the cell, and the part that didn't fit, because the cell was too narrow, was represented by an ellipsis (i.e. the "...") on the left, e.g.
"... ectory3\example.txt"
That way, if there were a lot of files in the same directory, the displayed text might show the full filename, providing it wasn't too long; instead of showing a lot of entries with only the left part of the path being displayed, with the result that they all displayed identically.
I realize I could do a call to find out how big a text string would be displayed at the current font, pitch, weight etc. Then, I might iterate until I found the maximum letters that would fit; and set it in the above code to only as much as would fit.
However, I'd rather use a QStyledItemDelegate and use setItemDelegateForColumn(), do something something similar; or use a stylesheet; such that the underlying data would be the full and correct pathname, but for it to display it being truly right-justified - even when the column is too narrow for the underlying text.