Results 1 to 3 of 3

Thread: Proper way to call custom dialogs

  1. #1
    Join Date
    Jul 2008
    Posts
    2
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Proper way to call custom dialogs

    Hi small problem here that holding me up, I am using PYQT4
    I am trying to call a second window from my QMainWindow, but I keep getting AttributeError: exec_
    This is a very basic example of what I am trying to do.
    One mainwindow with a pushbutton designed with Qt Designer,
    and a second dialog window with a couple of pushbuttons in it also designed in Qt Designer.
    both windows are set to ApplicationModal,
    I used pyuic4 to convert the .ui files to .py files,
    When the pushbutton is pressed the local function 'hit' tries to load to second window.
    Files are attached.
    Any help appreciated.

    Cheers Richard

    My start.py looks like this,


    Qt Code:
    1. import sys
    2. import MySQLdb
    3. from PyQt4 import QtCore, QtGui, QtSql
    4. from main import Ui_MainWindow
    5. from dialog import Ui_Dialog
    6. from PyQt4.QtGui import *
    7. from PyQt4.QtCore import *
    8.  
    9.  
    10.  
    11. class StartQT4(QtGui.QMainWindow):
    12. def __init__(self, parent=None):
    13. QtGui.QWidget.__init__(self, parent)
    14. self.ui = Ui_MainWindow()
    15. self.ui.setupUi(self)
    16.  
    17. QtCore.QObject.connect(self.ui.pushButton, QtCore.SIGNAL("clicked()"), self.hit)
    18.  
    19. def hit(self):
    20. print 'hit'
    21. dia = QtGui.QWidget()
    22. dia = dialog1()
    23. dia.show()
    24. dia.exec_()
    25.  
    26.  
    27. class dialog1(QtGui.QWidget):
    28. def __init__(self, parent=None):
    29. QtGui.QWidget.__init__(self, parent)
    30. self.di = Ui_Dialog()
    31. self.di.setupUi(self)
    32.  
    33.  
    34.  
    35.  
    36. if __name__ == "__main__":
    37. app = QtGui.QApplication(sys.argv)
    38. myapp = StartQT4()
    39. myapp.show()
    40. sys.exit(app.exec_())
    To copy to clipboard, switch view to plain text mode 
    Attached Files Attached Files

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Proper way to call custom dialogs

    exec() is part of QDialog and not QWidget - your widget should derive from the former.

  3. #3
    Join Date
    Jul 2008
    Posts
    2
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Proper way to call custom dialogs

    Ah thank you, very much.
    That did the trick.

    Cheers Richard

Similar Threads

  1. how to program custom Dialogs with return values
    By momesana in forum Qt Programming
    Replies: 2
    Last Post: 23rd December 2006, 01:37

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.