[PyQt] Have to close dialog boxes twice
Thorsten Kampe
thorsten at thorstenkampe.de
Sun Oct 21 09:33:32 BST 2007
Hi,
I've created a simple application with exit, help and about actions
that are available via menu and via toolbars. This application works
fine.
Now I tried to separate the layout from the code logic by using Qt
Designer and generating and importing an Ui file. This works fine,
too. Except that with the modified version I have to click twice on
the close or Ok button to close the dialog boxes and I have no idea
why. Can anyone give a clueless person a clue?
## The code
#! /usr/bin/env python
import sys
from PyQt4 import QtGui, \
QtCore
import ui_my_application
class MainWindow(QtGui.QMainWindow, ui_my_application.Ui_MainWindow):
def __init__(self):
QtGui.QMainWindow.__init__(self)
self.setupUi(self)
# set status bar
self.statusBar().showMessage(self.tr('Ready'))
# read settings
settings = QtCore.QSettings()
self.restoreGeometry(settings.value('Geometry').toByteArray())
def on_action_About_triggered(self):
QtGui.QMessageBox.about(self, self.tr('About Application'),
self.tr('My Application does something\n'
'This software comes without warranty, liability or support!'))
def on_actionE_xit_triggered(self):
settings = QtCore.QSettings()
settings.setValue('Geometry', QtCore.QVariant(self.saveGeometry()))
self.close()
def on_action_Help_triggered(self):
helpDialog = QtGui.QDialog(self)
browser = QtGui.QTextBrowser()
browser.append(self.tr('Help'))
layout = QtGui.QVBoxLayout()
layout.addWidget(browser)
helpDialog.setLayout(layout)
helpDialog.setWindowTitle(self.tr('Help'))
helpDialog.show()
app = QtGui.QApplication(sys.argv)
# Internationalization
qtTranslator = QtCore.QTranslator()
qtTranslator.load(':/qt.qm')
app.installTranslator(qtTranslator)
appTranslator = QtCore.QTranslator()
appTranslator.load(':/my_application.qm')
app.installTranslator(appTranslator)
#
app.setOrganizationName('Trolltech')
app.setApplicationName('My Application')
mainWin = MainWindow()
mainWin.show()
app.exec_()
## End of code
More information about the PyQt
mailing list