Unsolved Scale QGraphicsTextItem when a QGraphicsScene is resized?
-
Hello,
Is there a neat way to link the size of a QGraphicsTextItem to its parent QGraphicsScene?
I can call setScale upon a resize event but this seems very crude.
eg
import sys from PyQt4 import QtGui, QtCore from PyQt4.QtGui import * from PyQt4.QtCore import * class Window(QtGui.QWidget): def __init__(self): QtGui.QWidget.__init__(self) hbox = QtGui.QHBoxLayout() self.scene = QtGui.QGraphicsScene() self.view = QtGui.QGraphicsView() self.view.setScene(self.scene) hbox.addWidget(self.view) self.text = QtGui.QGraphicsSimpleTextItem() self.text.setText("Hello") self.scene.addItem(self.text) self.setLayout(hbox) self.setWindowTitle("Simple Scene") self.setGeometry(150, 150, 1000, 700) def resizeEvent(self, event): self.text.setScale(self.width()/100.0) class Game(QtCore.QObject): def __init__(self, parent=None): super(self.__class__, self).__init__(parent) # Create a gui object. self.gui = Window() self.gui.show() if __name__=='__main__': app = QtGui.QApplication(sys.argv) example = Game(app) sys.exit(app.exec_())
Is there a nicer text scaling method?
Thanks,
Jim