0
내 프로그램에 내 재고 시스템이 포함 된 MainWindow가 있습니다. "항목 추가"를 클릭했을 때 팝업 창이있는 대화 상자 창이 추가되었습니다. 성공적으로 대화 상자 창을 열 수 있지만 닫을 수 없습니다.Python에서 대화 상자를 닫을 수 없습니다 PyQt4
사용자가 대화 상자 창을 닫으려고하면 사용자가 실제로 창을 닫으려고하는지 묻는 메시지 상자가 표시됩니다. 현재, 나는 self.close()을 사용하고 있습니다. 우연한 종료를 막기 위해 만든 MessageBox를 닫고 IDE 나 작업 관리자를 사용하여 끝내지 않으면 Dialog 창을 닫지 않습니다.
Main.py에게
class Main(QtGui.QMainWindow):
def __init__(self):
QtGui.QMainWindow.__init__(self)
self.db = Database()
self.model = Model(self)
self.ui = MainWindow_ui()
self.ui.setupUi(self)
self.window = Ui_Dialog()
self.ui.addItem.clicked.connect(lambda : self.start_Form())
def start_Form(self):
window = QtGui.QDialog()
self.window.setupUi(window)
self.window.show()
def main():
app = QtGui.QApplication(sys.argv)
window = Main()
window.showMaximized()
sys.exit(app.exec_())
if __name__ == "__main__":
main()
AddItem.py (포함하는 대화 상자 창 코드)
def getNumber():
conn = sqlite3.connect('inventory.db')
c = conn.cursor()
c.execute('SELECT seq FROM sqlite_sequence')
itemNumber = c.fetchone()[0]
return int(itemNumber) + 1
class Ui_Dialog(QtGui.QDialog):
def __init__(self):
QtGui.QDialog.__init__(self)
self.setupUi(self)
def setupUi(self, Dialog):
Dialog.setObjectName(_fromUtf8("Dialog"))
Dialog.resize(413, 382)
self.buttonBox = QtGui.QDialogButtonBox(Dialog)
self.buttonBox.setStandardButtons(
QtGui.QDialogButtonBox.Cancel | QtGui.QDialogButtonBox.Ok | QtGui.QDialogButtonBox.Reset)
self.buttonBox.accepted.connect(self.accept)
self.buttonBox.rejected.connect(self.reject)
def retranslateUi(self, Dialog):
self.itemCode.setText(str(getNumber()))
def accept(self):
row = self.mapper.currentIndex()
self.mapper.submit()
self.main.model.insertRow(row)
self.mapper.setCurrentIndex(row)
self.close()
def reject(self):
ret = QtGui.QMessageBox.question(None, 'Close request', 'Are you sure you want to quit?',
QtGui.QMessageBox.Yes | QtGui.QMessageBox.No)
if ret == QtGui.QMessageBox.Yes:
self.close()
else:
pass
: 가상 메서드를 재정의 할 때
super
를 사용하여 기본 클래스 구현을 호출해야합니까? – lloydyu24@ lloydyu24. 새로운 질문을하십시오. – ekhumoro
https://stackoverflow.com/q/46129731/7342548 @ekhumoro – lloydyu24