Jump to content
Fórum Script Brasil
  • 0

Abrir janela modal - PyQT


Ninja2112

Question

Bom dia...

Estou utilizando Python 3.8 e instalei o QTDesigner. Criei uma janela main com menus que vão linkar p janelas modais. Não estou conseguindo realizar isso. Abre a main normalmente, mas quando clico no menu, ele fecha a aplicação. Aqui está o código que foi gerado :

Arquivo Principal.py

   

from PyQt5 import QtCore, QtGui, QtWidgets
from PyQt5.uic import loadUi
from PyQt5.QtWidgets import QApplication, QMainWindow, QPushButton, QDialog, QVBoxLayout, QLabel
import JanelaModal1, JanelaEnvRetDocs

class Ui_MainWindow(object):
    def setupUi(self, MainWindow):
        MainWindow.setObjectName("MainWindow")
        MainWindow.resize(800, 600)
        self.centralwidget = QtWidgets.QWidget(MainWindow)
        self.centralwidget.setObjectName("centralwidget")
        MainWindow.setCentralWidget(self.centralwidget)
        self.menubar = QtWidgets.QMenuBar(MainWindow)
        self.menubar.setGeometry(QtCore.QRect(0, 0, 800, 21))
        self.menubar.setObjectName("menubar")
        self.menuCONSULTAS = QtWidgets.QMenu(self.menubar)
        self.menuCONSULTAS.setObjectName("menuCONSULTAS")
        MainWindow.setMenuBar(self.menubar)
        self.statusbar = QtWidgets.QStatusBar(MainWindow)
        self.statusbar.setObjectName("statusbar")
        MainWindow.setStatusBar(self.statusbar)
        self.actionEnvRetDocs = QtWidgets.QAction(MainWindow)
        self.actionEnvRetDocs.setObjectName("actionEnvRetDocs")
        #self.actionEnvRetDocs.triggered.connect(self.abrir_janela_modal)
        self.actionEnvRetDocs.triggered.connect(self.abrirJanelaEnvRetDocs)

        self.actionDocsUnid = QtWidgets.QAction(MainWindow)
        self.actionDocsUnid.setObjectName("actionDocsUnid")
        self.actionDigitDocs = QtWidgets.QAction(MainWindow)
        self.actionDigitDocs.setObjectName("actionDigitDocs")
        self.actionDigitUnid = QtWidgets.QAction(MainWindow)
        self.actionDigitUnid.setObjectName("actionDigitUnid")
        self.menuCONSULTAS.addAction(self.actionEnvRetDocs)
        self.menuCONSULTAS.addAction(self.actionDocsUnid)
        self.menuCONSULTAS.addAction(self.actionDigitDocs)
        self.menuCONSULTAS.addAction(self.actionDigitUnid)
        self.menubar.addAction(self.menuCONSULTAS.menuAction())

        self.retranslateUi(MainWindow)
        QtCore.QMetaObject.connectSlotsByName(MainWindow)

    def retranslateUi(self, MainWindow):
        _translate = QtCore.QCoreApplication.translate
        MainWindow.setWindowTitle(_translate("MainWindow", "MainWindow"))
        self.menuCONSULTAS.setTitle(_translate("MainWindow", "CONSULTAS"))
        self.actionEnvRetDocs.setText(_translate("MainWindow", "Envio/Retorno Docs"))
        self.actionDocsUnid.setText(_translate("MainWindow", "Docs/Unidade"))
        self.actionDigitDocs.setText(_translate("MainWindow", "Digitação Docs"))
        self.actionDigitUnid.setText(_translate("MainWindow", "Digitação/Unidade"))

    def abrir_janela_modal(self):
        janela_modal = JanelaModal1.JanelaModal1()
        janela_modal.exec_()  # Exibe a janela modal

    def abrirJanelaEnvRetDocs(self):
        print("1")
        janela_modal1 = JanelaEnvRetDocs.Ui_jnlEnvRetDocs()
        janela_modal1.exec_()  # Exibe a janela modal


if __name__ == "__main__":
    import sys
    app = QtWidgets.QApplication(sys.argv)
    MainWindow = QtWidgets.QMainWindow()
    ui = Ui_MainWindow()
    ui.setupUi(MainWindow)
    MainWindow.show()
    sys.exit(app.exec_())

Arquivo JanelaEnvRetDocs.py

   

from PyQt5 import QtCore, QtGui, QtWidgets

class Ui_jnlEnvRetDocs(object):
    def setupUi(self, jnlEnvRetDocs):
        jnlEnvRetDocs.setObjectName("jnlEnvRetDocs")
        jnlEnvRetDocs.setWindowModality(QtCore.Qt.WindowModal)
        jnlEnvRetDocs.resize(489, 582)
        jnlEnvRetDocs.setModal(True)
        self.lblTitulo = QtWidgets.QLabel(jnlEnvRetDocs)
        self.lblTitulo.setGeometry(QtCore.QRect(180, 10, 181, 31))
        self.lblTitulo.setObjectName("lblTitulo")
        self.lblTipo = QtWidgets.QLabel(jnlEnvRetDocs)
        self.lblTipo.setGeometry(QtCore.QRect(20, 60, 51, 31))
        self.lblTipo.setObjectName("lblTipo")
        self.cmbTpDoc = QtWidgets.QComboBox(jnlEnvRetDocs)
        self.cmbTpDoc.setGeometry(QtCore.QRect(60, 70, 69, 22))
        self.cmbTpDoc.setObjectName("cmbTpDoc")
        self.cmbTpDoc.addItem("")
        self.cmbTpDoc.addItem("")
        self.lblDtInicial = QtWidgets.QLabel(jnlEnvRetDocs)
        self.lblDtInicial.setGeometry(QtCore.QRect(20, 120, 81, 21))
        self.lblDtInicial.setObjectName("lblDtInicial")
        self.calDtInicial = QtWidgets.QCalendarWidget(jnlEnvRetDocs)
        self.calDtInicial.setGeometry(QtCore.QRect(90, 120, 256, 101))
        self.calDtInicial.setObjectName("calDtInicial")
        self.lblDtFinal = QtWidgets.QLabel(jnlEnvRetDocs)
        self.lblDtFinal.setGeometry(QtCore.QRect(20, 260, 71, 21))
        self.lblDtFinal.setObjectName("lblDtFinal")
        self.calendarWidget = QtWidgets.QCalendarWidget(jnlEnvRetDocs)
        self.calendarWidget.setGeometry(QtCore.QRect(90, 260, 256, 183))
        self.calendarWidget.setObjectName("calendarWidget")
        self.btnEnviar = QtWidgets.QPushButton(jnlEnvRetDocs)
        self.btnEnviar.setGeometry(QtCore.QRect(220, 490, 75, 23))
        self.btnEnviar.setObjectName("btnEnviar")

        self.retranslateUi(jnlEnvRetDocs)
        QtCore.QMetaObject.connectSlotsByName(jnlEnvRetDocs)

    def retranslateUi(self, jnlEnvRetDocs):
        _translate = QtCore.QCoreApplication.translate
        jnlEnvRetDocs.setWindowTitle(_translate("jnlEnvRetDocs", "Consulta do Envio e Retorno de Documentos"))
        self.lblTitulo.setText(_translate("jnlEnvRetDocs", "ENVIO/RETORNO DE DOCUMENTOS"))
        self.lblTipo.setText(_translate("jnlEnvRetDocs", "Tipo :"))
        self.cmbTpDoc.setItemText(0, _translate("jnlEnvRetDocs", "DNs"))
        self.cmbTpDoc.setItemText(1, _translate("jnlEnvRetDocs", "DOs"))
        self.lblDtInicial.setText(_translate("jnlEnvRetDocs", "Data Inicial :"))
        self.lblDtFinal.setText(_translate("jnlEnvRetDocs", "Data Final :"))
        self.btnEnviar.setText(_translate("jnlEnvRetDocs", "CONSULTAR"))


if __name__ == "__main__":
    import sys
    app = QtWidgets.QApplication(sys.argv)
    jnlEnvRetDocs = QtWidgets.QDialog()
    ui = Ui_jnlEnvRetDocs()
    ui.setupUi(jnlEnvRetDocs)
    jnlEnvRetDocs.show()
    sys.exit(app.exec_())

O que estou fazendo errado ?

Link to comment
Share on other sites

0 answers to this question

Recommended Posts

There have been no answers to this question yet

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Answer this question...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.



  • Forum Statistics

    • Total Topics
      152.1k
    • Total Posts
      651.9k
×
×
  • Create New...