Results 1 to 4 of 4

Thread: opening a second window

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Feb 2010
    Posts
    96
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows
    Thanks
    4
    Thanked 5 Times in 5 Posts

    Default Re: opening a second window

    I think your code is pretty messy, to start with, making it harder to work with. Take a look at some of my code, because I am sure it will help you.

    main.py:
    Qt Code:
    1. # Version: Traipse 'Pious-Paladin'
    2. # $Id: main.py,v Traipse 'Pious-Paladin' prof.ebral Exp $
    3. #
    4. # Description: This is the main entry point of the oprg application
    5.  
    6. from PyQt4 import QtCore, QtGui
    7. from os import sep
    8.  
    9. from map_engine.map_dock import MapDock
    10. from chat_engine.chat_dock import ChatDock
    11. from net_engine.plist_dock import PListDock
    12. from net_engine.client_gear import ClientGear
    13. from tree_engine.tree_dock import TreeDock
    14. from tool_gears.path_gear import PathTool, path
    15.  
    16. PathTool().load_paths(path)
    17.  
    18. class MainWindow(QtGui.QMainWindow):
    19.  
    20. def __init__(self):
    21. super(MainWindow, self).__init__()
    22. self.setWindowIcon(QtGui.QIcon(path['core_images'] + 'traipse-logo-2.png'))
    23. self.client = ClientGear(self)
    24. self.createActions()
    25. self.createDocks()
    26. self.StatusBar('Ready')
    27. self.createToolBar()
    28. self.createStyle()
    29. self.setCentralWidget(self.center1)
    30.  
    31. def createDocks(self):
    32. #Game Tree Docking Bay
    33. self.treeDock = QtGui.QDockWidget("Dock-Game Tree", self)
    34. self.center4 = TreeDock(self, self.client)
    35. self.treeDock.setWidget(self.center4)
    36. self.treeDock.setFeatures(QtGui.QDockWidget.DockWidgetMovable |
    37. QtGui.QDockWidget.DockWidgetFloatable)
    38. self.center4.add('Child-2')
    39. self.addDockWidget(QtCore.Qt.LeftDockWidgetArea, self.treeDock)
    40.  
    41. #Player List Docking Bay
    42. self.PlayerList = QtGui.QDockWidget("Dock-Player List", self)
    43. self.center3 = PListDock(self, self.client)
    44. self.PlayerList.setWidget(self.center3)
    45. self.PlayerList.setFeatures(QtGui.QDockWidget.DockWidgetMovable |
    46. QtGui.QDockWidget.DockWidgetFloatable)
    47. self.center3.add(2, 'Player-2', 'Idle')
    48. self.center3.add(3, 'Player-3', 'Typing')
    49. self.addDockWidget(QtCore.Qt.LeftDockWidgetArea, self.PlayerList)
    50.  
    51. #Map Docking Bay
    52. self.mapDock = QtGui.QDockWidget("Dock-Map", self)
    53. self.center1 = MapDock(self, self.client)
    54. self.mapDock.setWidget(self.center1)
    55. self.mapDock.setFeatures(QtGui.QDockWidget.DockWidgetMovable |
    56. QtGui.QDockWidget.DockWidgetFloatable)
    57. self.addDockWidget(QtCore.Qt.RightDockWidgetArea, self.mapDock)
    58. self.mapDock.hide()
    To copy to clipboard, switch view to plain text mode 

    This is the Main file. This is my anchor to all my other UI scripts. This is not a complete version, but here you can see I am creating a proxy Player List and proxy Game Tree. I want you to look at the Map Docking Bay. It inserts the MapDock class, passing the parent and the future network client.

    map_dock.py
    Qt Code:
    1. from PyQt4 import QtCore, QtGui
    2. from tool_gears.path_gear import path
    3. from map_engine.tool_gear import mapToolGear
    4. from map_engine.map_gear import MapDocket
    5.  
    6. class MapDock(QtGui.QMainWindow):
    7.  
    8. def __init__(self, parent, client):
    9. super(MapDock, self).__init__()
    10. self.parent = parent; self.client = client
    11. self.createMap()
    12. self.createToolBar()
    13. self.setCentralWidget(self.mapDocket)
    14.  
    15. def createToolBar(self):
    16. self.ToolBay = mapToolGear(self.parent)
    17. self.addToolBar(QtCore.Qt.BottomToolBarArea, self.ToolBay)
    18.  
    19. ## Map Docket
    20. def createMap(self):
    21. self.mapDocket = QtGui.QWidget()
    22. layout = QtGui.QGridLayout()
    23. self.mapView = MapDocket()
    24. layout.addWidget(self.mapView)
    25. self.mapDocket.setLayout(layout)
    26.  
    27. def createMapEditor(self):
    28. self.parent.mapEditor = QtGui.QDialog()
    29. layout = QtGui.QGridLayout()
    30. self.parent.mapEditView = MapDocket()
    31. layout.addWidget(self.parent.mapEditView)
    32. self.parent.mapEditor.setLayout(layout)
    33. self.parent.mapEditor.show()
    34.  
    35. def empty(self):
    36. pass
    To copy to clipboard, switch view to plain text mode 

    Here is the entirety of my map_dock file, which contains the MapDock class. Can you see how I am re using the MapDocket() class to create a map for the core software and a map for the map editor? Maybe I am wrong, but I think that is what you are trying to do. Notice how the second one is rooted in the parent?

    I would suggest you look at your Ui_Dialog Classes. They don't need to declared (object), the should be declared (QtGui.QDialog). I am also not sure why you would create a setupUI function and not use the pre-built __init__ function. I would suggest you use __init__ and then you can create room for you parent object, plus you can build the UI just by calling the class each time.

  2. #2
    Join Date
    Feb 2010
    Posts
    12
    Qt products
    Qt4 PyQt3 PyQt4
    Platforms
    Unix/X11

    Default Re: opening a second window

    thanks you have given me a lot to take in.

    I only had a few minutes tonight so will look it over again tomorrow and post any questions or thoughts then.

    thanks for the reply

  3. #3
    Join Date
    Feb 2010
    Posts
    96
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows
    Thanks
    4
    Thanked 5 Times in 5 Posts

    Default Re: opening a second window

    You are welcome.

Similar Threads

  1. Qt 4.6.0: Opening a dialog from a main window
    By dmginc in forum Qt Programming
    Replies: 3
    Last Post: 14th January 2010, 13:16
  2. Opening a new window
    By k12yp70n in forum Newbie
    Replies: 1
    Last Post: 26th March 2009, 16:31
  3. Opening a shapefile
    By peace_comp in forum Qt Programming
    Replies: 1
    Last Post: 1st May 2008, 21:59
  4. Opening an URL that contains accents
    By Nyphel in forum Newbie
    Replies: 8
    Last Post: 26th June 2007, 09:13
  5. Help with opening many pictures
    By philipp1 in forum Qt Programming
    Replies: 3
    Last Post: 14th October 2006, 01:13

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
  •  
Qt is a trademark of The Qt Company.