[PyQt] Problem calling a window
Sergio Jovani
lesergi at gmail.com
Fri Jan 16 00:04:44 GMT 2009
Hi,
If you want to call a QMainWindow from a QDialog you have to set a
parent. exec_() gets attribute error because I thought it was a
QDialog :P
Try with this:
wndMain = Pro2MainWindow(self) # <--- set as parent QDialog
wndMain.showMaximized()
self.hide()
2009/1/15 Sandro Dutra <hexodin at gmail.com>:
> Sorry for the delay... it's the time, it's the time...
>
> I used Eric4 and QtDesigner, so the Pro2MainWindow it's only the window
> without the widgets (I only want to test the call), here's the code:
>
> ---Pro2MainWindow Code---
> # -*- coding: utf-8 -*-
>
> """
> Module implementing Pro2MainWindow.
> """
>
> from PyQt4.QtGui import QMainWindow
> from PyQt4.QtCore import pyqtSignature
>
> from Ui_Pro2MainWindow import Ui_Pro2MainWindow
>
> class Pro2MainWindow(QMainWindow, Ui_Pro2MainWindow):
> """
> Class documentation goes here.
> """
> def __init__(self, parent = None):
> """
> Constructor
> """
> QMainWindow.__init__(self, parent)
> self.setupUi(self)
>
> The setupUi, only call the definitions of the ui generated by QtDesigner,
> and here's the complete code for the login screen:
> # -*- coding: utf-8 -*-
>
> """
> Module implementing DialogPro2Login.
> """
>
> from PyQt4.QtGui import QDialog, QMessageBox, QApplication
> from PyQt4.QtCore import pyqtSignature
>
> from Ui_Pro2Login import Ui_DialogPro2Login
> from Pro2MainWindow import Pro2MainWindow
> from db.database import Pro2db
>
> import MySQLdb, sys
>
> class DialogPro2Login(QDialog, Ui_DialogPro2Login):
> """
> Class documentation goes here.
> """
> def __init__(self, parent = None):
> """
> Constructor
> """
> QDialog.__init__(self, parent)
> self.setupUi(self)
>
> @pyqtSignature("")
> def on_pushButton_enter_clicked(self):
> user = self.lineEdit_user.text()
> passw = self.lineEdit_passw.text()
> if user == "" or passw == "":
> QMessageBox.information(self, "ERRO", u"Por favor, entre com o
> usuário e senha.", "OK")
> else:
> try:
> p2db = Pro2db(str(user), str(passw)) ### Here is where I
> want to call the mainwindow ####
> wndMain = Pro2MainWindow()
> wndMain.exec_()
> wndMain.showMaximized()
> self.hide()
> ##############################
> except MySQLdb.Error, error_code:
> if error_code[0] == 1045:
> message = u"Acesso negado para o usuário: %s" %user
> elif error_code[0] == 2003:
> message = u"Não foi possível realizar a conexão."
> else:
> message = u"Erro desconhecido.\nCódigo administrativo:
> %s - %s." %(error_code[0], error_code[1])
> QMessageBox.information(self, "Falha no acesso", u"O
> servidor informa:\n%s" %message, "OK")
>
> @pyqtSignature("")
> def on_pushButton_exit_clicked(
> self):
> self.close()
>
> If you need more info tell me,
> Thanks for the attention to a so noob problem.
> Sandro Dutra - Brazil.
> _______________________________________________
> PyQt mailing list PyQt at riverbankcomputing.com
> http://www.riverbankcomputing.com/mailman/listinfo/pyqt
>
More information about the PyQt
mailing list