我正在使用python和pyqt。我有一个我想暂时隐藏的对话框。致电后
dlg.hide()
我试着打电话
dlg.show()
但没有任何反应。它永远不会重新显示。
我是pyqt的新手,所以非常感谢任何帮助。
提前致谢。
答案 0 :(得分:0)
您正在寻找使对话框模态化的exec_
方法,看看它是如何工作的:
#!/usr/bin/env python
#-*- coding:utf-8 -*-
from PyQt4 import QtCore, QtGui
class myDialog(QtGui.QDialog):
def __init__(self, parent=None):
super(myDialog, self).__init__(parent)
self.dialog = None
self.buttonShow = QtGui.QPushButton(self)
self.buttonShow.setText("Show Dialog")
self.buttonShow.clicked.connect(self.on_buttonShow_clicked)
self.buttonHide = QtGui.QPushButton(self)
self.buttonHide.setText("Close")
self.buttonHide.clicked.connect(self.on_buttonHide_clicked)
self.layout = QtGui.QVBoxLayout(self)
self.layout.addWidget(self.buttonShow)
self.layout.addWidget(self.buttonHide)
@QtCore.pyqtSlot()
def on_buttonHide_clicked(self):
self.accept()
@QtCore.pyqtSlot()
def on_buttonShow_clicked(self):
self.dialog = myDialog(self)
self.dialog.exec_()
class myWindow(QtGui.QWidget):
def __init__(self, parent=None):
super(myWindow, self).__init__(parent)
self.buttonShow = QtGui.QPushButton(self)
self.buttonShow.setText("Show Dialog")
self.buttonShow.clicked.connect(self.on_buttonShow_clicked)
self.layout = QtGui.QVBoxLayout(self)
self.layout.addWidget(self.buttonShow)
self.dialog = myDialog(self)
@QtCore.pyqtSlot()
def on_buttonHide_clicked(self):
self.dialog.accept()
@QtCore.pyqtSlot()
def on_buttonShow_clicked(self):
self.dialog.exec_()
if __name__ == "__main__":
import sys
app = QtGui.QApplication(sys.argv)
app.setApplicationName('myWindow')
main = myWindow()
main.show()
sys.exit(app.exec_())