我在视图中的矩形项上方添加了simpleText。当我放大/缩小文本时,文本会调整大小以保持可读性。但是,它会从文本的左上角调整到右下角。所以文本最终会经过我的rectItem。在
有人对如何定位/对齐要调整大小的文本从左下角到右上角有什么建议吗?在
我调用self.text.setFont(QFont("Arial",newSize)
来调整文本大小。在
谢谢!在
编辑1:
我做了一个粗略的示例代码来显示这个问题—它不会运行……但是您可以看到,当文本展开时,它将覆盖其父项:
以下两个功能一起使用
class mySimpleText(QGraphicsSimpleTextItem):
def __init__(self, parent):
super(mySimpleText,self).__init__(self,parent=parent)
self.setText("HEY SEXY")
#self.setPlainText("HEY SEXYYY") # using TextItem
class mySpecialRect(QGraphicsRectItem):
def __init__(self,myManager,rect):
super(mySpecialRect,self).__init__(self,rect)
self.myManager = myManager
self.myTextLabel = mySimpleText(self)
self.myTextLabel.setPos(self.boundingRect().x()-50,self.boundingRect().y())
self.initSignals()
def initSignals(self):
self.myManager.userFontChanged.connect(self.fontChanged)
def fontChanged(self,size):
self.myTextLabel.setFont(QFont("Arial",size))
这是我的班级发送信号:
^{pr2}$
目前没有回答
相关问题 更多 >
编程相关推荐