gpt4 book ai didi

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

转载 作者:太空狗 更新时间:2023-10-30 01:57:54 26 4
gpt4 key购买 nike

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_()

我正在使用 PySide 1.2.1 和 Qt 4.8.6。

最佳答案

我发现这是一个旧的bug .幸运的是有一个 workaround .也许对其他人也有用:

代替 Qt.AlignRight | Qt.AlignVCenter 使用 int(Qt.AlignRight | Qt.AlignVCenter)

关于python - 如何在 QAbstractTableModel 中右对齐和垂直居中?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35175210/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com