<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<style type="text/css" style="display:none;"><!-- P {margin-top:0;margin-bottom:0;} --></style>
</head>
<body dir="ltr">
<div id="divtagdefaultwrapper" style="font-size:12pt;color:#000000;font-family:Calibri,Helvetica,sans-serif;" dir="ltr">
<p>Hello,</p>
<p><br>
</p>
<p>Is there a neat way to link the size of a QGraphicsSimpleTextItem to its parent QGraphicsScene?</p>
<p><br>
</p>
<p>I can call setScale upon a resize event but this seems very crude.</p>
<p><br>
</p>
<p>eg Here's a working example:</p>
<p><br>
</p>
<p><br>
</p>
<p></p>
<div>import sys</div>
<div>from PyQt4 import QtGui, QtCore</div>
<div>from PyQt4.QtGui import *</div>
<div>from PyQt4.QtCore import *</div>
<div> </div>
<div>class Window(QtGui.QWidget):</div>
<div> signal_shown = QtCore.pyqtSignal()</div>
<div> def __init__(self):</div>
<div> QtGui.QWidget.__init__(self)</div>
<div> hbox = QtGui.QHBoxLayout() </div>
<div> </div>
<div> self.scene = QtGui.QGraphicsScene()</div>
<div> self.view = QtGui.QGraphicsView()</div>
<div> self.view.setScene(self.scene)</div>
<div> hbox.addWidget(self.view)</div>
<div> </div>
<div> self.text = QtGui.QGraphicsSimpleTextItem()</div>
<div> self.text.setText("Hello")</div>
<div> </div>
<div> self.scene.addItem(self.text)</div>
<div> </div>
<div> # set central widget for the application</div>
<div> self.setLayout(hbox)</div>
<div> self.setWindowTitle("Simple Scene")</div>
<div> self.setGeometry(150, 150, 1000, 700)</div>
<div> </div>
<div> def resizeEvent(self, event):</div>
<div><span style="font-size: 12pt;"> self.text.setScale(self.width()/100.0)</span><br>
</div>
<div> </div>
<div>class Game(QtCore.QObject):</div>
<div> </div>
<div> def __init__(self, parent=None):</div>
<div> super(self.__class__, self).__init__(parent)</div>
<div> </div>
<div> # Create a gui object.</div>
<div> self.gui = Window()</div>
<div> </div>
<div> self.gui.show()</div>
<div> </div>
<div>if __name__=='__main__':</div>
<div> app = QtGui.QApplication(sys.argv)</div>
<div> example = Game(app)</div>
<div> sys.exit(app.exec_())</div>
<br>
<p></p>
<p><br>
</p>
<p><br>
</p>
<p>Is there a nicer text scaling method?</p>
<p><br>
</p>
<p>Thanks,</p>
<p><br>
</p>
<p>Jim</p>
</div>
</body>
</html>