QDialog 위젯을 만들었습니다. 내 문제는 QDialog를 종료 할 수 없다는 것입니다. 버튼 중 하나를 누르면 QDialog가 "숨기기"로 설정됩니다. 다음은 코드의 일부입니다. 그것은 실행 가능합니다. 내가 뭘 잘못하고 있는지 모르겠다. 어쩌면 당신 중 하나가 말해 줄 수 있습니다.PyQt : 어떻게 QDialog를 종료 할 수 있습니까?
from PyQt4.QtCore import *
from PyQt4.QtGui import *
import sys
class MyClass(QDialog):
def __init__(self, parent=None):
QWidget.__init__(self, parent)
# init
# ------------------------------------------------
self.setMinimumWidth(600)
self.setWindowTitle("Select Dingsda")
self.layout = QVBoxLayout()
self.setLayout(self.layout)
self.layoutWidget = QWidget(self)
self.liste = []
# widgets and layouts
# ------------------------------------------------
tempLayout = QHBoxLayout()
self.cancelButton = QPushButton("Cancel")
self.connect(self.cancelButton, SIGNAL('clicked()'), self.cancel)
self.addSelectedButton = QPushButton("Add Selected")
self.connect(self.addSelectedButton, SIGNAL('clicked()'), self.addSelected)
tempLayout.addStretch()
tempLayout.addWidget(self.cancelButton)
tempLayout.addWidget(self.addSelectedButton)
self.layout.addLayout(tempLayout)
# test-data
# ------------------------------------------------
# methods
# ------------------------------------------------
def cancel(self):
self.close()
def addSelected(self):
self.liste = ["1", "2", "3", "4", "5"]
self.accept()
def exec_(self):
if QDialog.exec_(self) == QDialog.Accepted:
return self.liste
else:
return []
def test():
app = QApplication([""])
form = MyClass()
i = form.exec_()
print i
sys.exit(app.exec_())
#-------------------------------------------------------------------------------
# main
#-------------------------------------------------------------------------------
if __name__ == "__main__":
test()
오, 젠장. 그 대답 일 수 있습니다. 지금은 유일한 창문입니다. 아직 작업 중이며 테스트 중이기 때문입니다. 이제 나는 어리 석다. 어쨌든 답변 해 주셔서 감사합니다. – user427305