Results 1 to 7 of 7

Thread: Opening another created gui pyqt

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #4
    Join Date
    Jan 2010
    Location
    Istanbul, Turkey
    Posts
    10
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Opening another created gui pyqt

    I'm sorry, I just pasted a code where I used Qt Designer and imported the resulting gui.py (pyuic4 gui.ui gui.py) file. So forget it if you don't use Qt Designer. If you use it, you might want to take a look at here (13.1 Using the Generated Code)

    Here's a minimal example where all the stuff is done by code:
    Qt Code:
    1. import sys
    2. from PyQt4.QtCore import *
    3. from PyQt4.QtGui import *
    4.  
    5. class OtherWindow(QMainWindow):
    6. def __init__(self):
    7. QMainWindow.__init__(self)
    8. layout = QHBoxLayout()
    9. lineEdit = QLineEdit()
    10. lineEdit.setText("Just to fill up the dialog")
    11. layout.addWidget(lineEdit)
    12.  
    13. self.widget = QWidget()
    14. self.widget.setLayout(layout)
    15.  
    16. self.setCentralWidget(self.widget)
    17. self.setWindowTitle("Win2")
    18.  
    19. class MainWindow(QMainWindow):
    20. def __init__(self):
    21. QMainWindow.__init__(self)
    22. layout = QHBoxLayout()
    23. button = QPushButton()
    24. layout.addWidget(button)
    25.  
    26. self.widget = QWidget()
    27. self.widget.setLayout(layout)
    28.  
    29. self.setCentralWidget(self.widget)
    30. self.setWindowTitle("Win1")
    31.  
    32. self.connect(button, SIGNAL('clicked()'), self.newWindow)
    33. def newWindow(self):
    34. self.myOtherWindow = OtherWindow()
    35. self.myOtherWindow.show()
    36.  
    37. if __name__ == "__main__":
    38.  
    39. app = QApplication(sys.argv)
    40. mainWindow = MainWindow()
    41. mainWindow.setGeometry(100, 100, 200, 200)
    42. mainWindow.show()
    43. sys.exit(app.exec_())
    To copy to clipboard, switch view to plain text mode 

    So the key point is the latter part:
    Qt Code:
    1. ...
    2. self.connect(button, SIGNAL('clicked()'), self.newWindow)
    3. def newWindow(self):
    4. self.myOtherWindow = OtherWindow()
    5. self.myOtherWindow.show()
    To copy to clipboard, switch view to plain text mode 

    In the init of MainWindow, you connect the clicked signal of button to newWindow method.

    newWindow method just creates a second window and shows it. That's it.
    Last edited by aladagemre; 18th January 2010 at 10:38.

Similar Threads

  1. Replies: 5
    Last Post: 10th November 2009, 15:46
  2. Opening a browser in MAC
    By gren15 in forum Newbie
    Replies: 2
    Last Post: 30th June 2009, 16:54
  3. opening PPT files in Qt
    By jay in forum Qt Programming
    Replies: 5
    Last Post: 14th May 2009, 12:20
  4. opening webpage using qt....
    By anupamgee in forum Qt Programming
    Replies: 8
    Last Post: 20th April 2009, 11:13
  5. Opening a shapefile
    By peace_comp in forum Qt Programming
    Replies: 1
    Last Post: 1st May 2008, 20:59

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.