小编Nor*_*bők的帖子

如何在QAbstractTableModel中右对齐和垂直对齐?

Qt.AlignRight右对齐文本,但把它放到了右上角.这Qt.AlignRight | Qt.AlignVCenter不起作用.将它放入左上角.

有没有办法让文本保持垂直居中并同时右对齐?

代码示例:

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_()
Run Code Online (Sandbox Code Playgroud)

我正在使用PySide 1.2.1和Qt 4.8.6.

python pyside

4
推荐指数
1
解决办法
1135
查看次数

标签 统计

pyside ×1

python ×1