Results 1 to 1 of 1

Thread: Multiple windows

  1. #1
    Join Date
    Apr 2009
    Posts
    2
    Qt products
    Platforms
    MacOS X Unix/X11

    Default Multiple windows

    Hello,

    I am using PyQt4 to visualize a fish that changes its shape:

    Qt Code:
    1. def main():
    2.  
    3. app = QtGui.QApplication(sys.argv)
    4.  
    5. scene = QtGui.QGraphicsScene()
    6. scene.setSceneRect( -2.0, -2.0, 4.0, 4.0)
    7.  
    8. fish = Fish()
    9. fish.setPos(0.0, 0.0)
    10. scene.addItem(fish)
    11.  
    12. view = QtGui.QGraphicsView(scene)
    13. view.setRenderHint(QtGui.QPainter.Antialiasing)
    14. view.scale(150,150)
    15.  
    16. view.show()
    17. view.raise_()
    18.  
    19. sys.exit(app.exec_())
    To copy to clipboard, switch view to plain text mode 
    So far so good. This code works as expected. It opens up a window, with the fish in it.

    Now I would like to simulate several fish, each placed in their own separate main window.

    So the first step I did was to define a MainWindow class as follows:

    Qt Code:
    1. class MainWindow(QtGui.QMainWindow):
    2.  
    3. def __init__(self):
    4. QtGui.QMainWindow.__init__(self)
    5. scene = QtGui.QGraphicsScene()
    6. scene.setSceneRect( -2.0, -2.0, 4.0, 4.0)
    7.  
    8. fish = Fish()
    9. fish.setPos(0, 0)
    10. scene.addItem(fish)
    11.  
    12. view = QtGui.QGraphicsView(scene)
    13. view.setRenderHint(QtGui.QPainter.Antialiasing)
    14. view.scale(150,150)
    15. self.setCentralWidget(view)
    16.  
    17. def main():
    18. app = QtGui.QApplication(sys.argv)
    19. win = MainWindow()
    20. win.show()
    21. win.raise_()
    22. sys.exit(app.exec_())
    To copy to clipboard, switch view to plain text mode 

    but for some reason this just displays an empty window with no view in it. What am I doing wrong?
    Last edited by bgturk; 23rd April 2009 at 10:11.

Similar Threads

  1. how to create multiple windows in QT
    By durgarao in forum Qt Tools
    Replies: 1
    Last Post: 9th January 2009, 14:47
  2. Multiple versions of Qt in Windows?
    By gfunk in forum Qt Programming
    Replies: 1
    Last Post: 27th August 2007, 19:07
  3. Multiple Windows -> Advice needed
    By vokal in forum Newbie
    Replies: 2
    Last Post: 8th January 2007, 08:40
  4. QGLWidget and multiple windows
    By ToddAtWSU in forum Qt Programming
    Replies: 1
    Last Post: 21st November 2006, 13:38

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.