Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Game Development
  4. Scale QGraphicsTextItem when a QGraphicsScene is resized?

Scale QGraphicsTextItem when a QGraphicsScene is resized?

Scheduled Pinned Locked Moved Unsolved Game Development
1 Posts 1 Posters 906 Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • J Offline
    J Offline
    Jimbo
    wrote on last edited by
    #1

    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

    1 Reply Last reply
    0

    • Login

    • Login or register to search.
    • First post
      Last post
    0
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Get Qt Extensions
    • Unsolved