Issue
The Qt.AlignRight
right aligns the text but puts it into the right-top corner. The Qt.AlignRight | Qt.AlignVCenter
doesn't work. Puts it into the left-top corner.
Is there a way to keep the text vertically centered and right aligned at the same time?
Code sample:
from PySide.QtCore import *
from PySide.QtGui import *
class TableView(QTableView):
def __init__(self):
QTableView.__init__(self)
self.setModel(TableModel(self))
class TableModel(QAbstractTableModel):
def rowCount(self, parent):
return 1
def columnCount(self, parent):
return 2
def data(self, index, role):
if role == Qt.DisplayRole:
return 'text'
elif role == Qt.TextAlignmentRole:
return Qt.AlignRight | Qt.AlignVCenter
app = QApplication([])
w = TableView()
w.show()
app.exec_()
I'm using PySide 1.2.1 with Qt 4.8.6.
Solution
I found that it's an old bug. Luckily there is a workaround. Maybe useful for others too:
Instead of Qt.AlignRight | Qt.AlignVCenter
use int(Qt.AlignRight | Qt.AlignVCenter)
.
Answered By - Norbert Sebők
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.