我必须给QGraphicsTextItem
写一些波斯语文本,但我找不到如何让QGraphicsTextItem
写RightToLeft
有人能帮我吗?。
我试过这种方法,但对我不起作用:
class DiagramTextItem(QtGui.QGraphicsTextItem):
def __init__(self, parent=None, scene=None):
super(DiagramTextItem, self).__init__(parent, scene)
doc =QtGui.QTextDocument ('''شسشس
یییییگ''')
txtOpt = QtGui.QTextOption()
txtOpt.setAlignment(QtCore.Qt.AlignRight)
doc.setDefaultTextOption(txtOpt)
谢谢。
看起来您可以将QTextOption.setTextDirection与Qt.RightToLeft.一起使用
但请注意,在设置文本之前,您可能需要设置方向:
class DiagramTextItem(QtGui.QGraphicsTextItem):
def __init__(self, parent=None, scene=None):
super(DiagramTextItem, self).__init__(parent, scene)
doc = QtGui.QTextDocument()
txtOpt = QtGui.QTextOption()
txtOpt.setTextDirection(QtCore.Qt.RightToLeft)
doc.setPlainText('''شسشس
یییییگ''')
如果不起作用,请尝试将光标设置在QGraphicsTextItem
:上
class DiagramTextItem(QtGui.QGraphicsTextItem):
def __init__(self, parent=None, scene=None):
super(DiagramTextItem, self).__init__(parent, scene)
cursor = self.textCursor()
format = cursor.charFormat()
format.setLayoutDirection(QtCore.Qt.RightToLeft)
cursor.setFormat(format)
self.setTextCursor(cursor)
self.setPlainText('''شسشس
یییییگ''')