Results 1 to 4 of 4

Thread: How to open a 2nd form after a button is clicked in the 1st - PyQT

  1. #1
    Join Date
    Feb 2011
    Posts
    4
    Qt products
    PyQt3 PyQt4
    Platforms
    Unix/X11 Windows

    Default How to open a 2nd form after a button is clicked in the 1st - PyQT

    I have read this thread and also search and found the FAQ here.

    But the problem with the first thread mentioned above is that it was written using one source file. I've been trying to google for hours now and search for a solution to connect two forms I made using eric4 + QtDesigner. Most of the tutorials I found uses only one code like that of the first thread mentioned above.

    The FAQ that was pointed out is in C++ I believe but I can't seem to deduce it to code it up for PyQt

    Is it by chance possible the dialogue code made by the first form will then connect to the second form in PyQt (in eric4)? I generated the Dialog code like it was mentioned here at the eric4 web browser tutorial.

    After I made a new Dialog form, I want the Main Window form to connect to the Dialog form I made but was stuck now how to do it. Would it be alright by chance to ask how to code it?

    My apologies as I'm quite new to this and thank you in advance *bows deeply*

  2. #2
    Join Date
    Feb 2011
    Posts
    4
    Qt products
    PyQt3 PyQt4
    Platforms
    Unix/X11 Windows

    Default Re: How to open a 2nd form after a button is clicked in the 1st - PyQT

    Okay, I think I kinda got it - I imported the class of the second form. This is somewhat the codes (but I changed the names of the classes mostly)

    form1.py
    Qt Code:
    1. from PyQt4.QtGui import QMainWindow
    2. from PyQt4.QtCore import pyqtSignature
    3.  
    4. from Ui_form1 import Ui_MainWindow
    5.  
    6. from ui.form2 import FormTwo
    7.  
    8. class FormOne(QMainWindow, Ui_MainWindow):
    9. """
    10. Class documentation goes here.
    11. """
    12. def __init__(self, parent = None):
    13. """
    14. Constructor
    15. """
    16. QMainWindow.__init__(self, parent)
    17. self.setupUi(self)
    18.  
    19. @pyqtSignature("")
    20. def on_button_released(self):
    21. """
    22. Slot documentation goes here.
    23. """
    24. FT = FormTwo()
    25. FT.show()
    To copy to clipboard, switch view to plain text mode 

    form2.py
    Qt Code:
    1. from PyQt4.QtGui import QDialog
    2. from PyQt4.QtCore import pyqtSignature
    3.  
    4. from Ui_form2 import Ui_Dialog
    5.  
    6. class FormTwo(QDialog, Ui_Dialog):
    7. """
    8. Class documentation goes here.
    9. """
    10. def __init__(self, parent = None):
    11. """
    12. Constructor
    13. """
    14. QDialog.__init__(self, parent)
    15. self.setupUi(self)
    To copy to clipboard, switch view to plain text mode 

    __init__.py
    Qt Code:
    1. from PyQt4 import QtCore, QtGui
    2. from ui.form1 import FormOne
    3.  
    4. if __name__ == "__main__":
    5. import sys
    6. app = QtGui.QApplication(sys.argv)
    7. ui = FormOne()
    8. ui.show()
    9. sys.exit(app.exec_())
    To copy to clipboard, switch view to plain text mode 

    There is a new problem though that the 2nd form doesn't stay at all and closes immediately after I click the button on the first form. Would it be alright to ask how to correct and solve this?

  3. #3
    Join Date
    Feb 2011
    Posts
    4
    Qt products
    PyQt3 PyQt4
    Platforms
    Unix/X11 Windows

    Default Re: How to open a 2nd form after a button is clicked in the 1st - PyQT

    Finally got it. It should be:

    self.FT = FormTwo()
    self.FT.show()

    so that the next form would appear. Thanks anyway guys Posting just in case for others if they see this :P

    PS: Now that I realize it, that was embarrassing OTL;;

  4. #4
    Join Date
    Jun 2012
    Posts
    1
    Platforms
    Windows

    Default Re: How to open a 2nd form after a button is clicked in the 1st - PyQT

    once the second form is created, make a button for the new form. this code is actually one of the easiest. if you want to hide the current window. (for this example I will just use the genaric form2)

    me.hide()
    form2.Show()

Similar Threads

  1. Replies: 3
    Last Post: 23rd December 2010, 06:55
  2. To open new QML when pushButton is clicked
    By soumya in forum Qt Programming
    Replies: 0
    Last Post: 3rd May 2010, 05:51
  3. How can i open a dialog when clicked on treewidget?
    By newermind in forum Qt Programming
    Replies: 2
    Last Post: 4th May 2009, 11:13
  4. Replies: 10
    Last Post: 6th July 2008, 09:46
  5. Replies: 3
    Last Post: 13th May 2007, 20:55

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.