views:

65

answers:

1

I have QStandardItemModel and QTableView. I want to have the number align to the right. How can i specify this in pyqt?

Now i have it like this (see ID) http://simple-database-explorer.googlecode.com/files/Main2.jpg

Working example:

self.model.setData(self.model.index(i, j, QtCore.QModelIndex()), value, role=0)
if isNumber(value):
    self.model.setData(self.model.index(i, j, QtCore.QModelIndex()), QtCore.QVariant(QtCore.Qt.AlignRight), QtCore.Qt.TextAlignmentRole)
+1  A: 

Are you using QStandardItems as well? Then you can use setTextAlignment.

Update

Using setData:

model.setData(index, QtCore.QVariant(QtCore.Qt.AlignRight),
              QtCore.Qt.TextAlignmentRole)
Ivo
No, using setData. Will try it out
hugo24
In that case, use setData(..., Qt.TextAlignmentRole).
Ivo
could u pls provide a real example :) dont get the API
hugo24
aha tnx. I was confused since i thought i should call setData only once. A working example is in my question.
hugo24
Sorry for the confusion then :)
Ivo