在上一篇里,实现的模态对话框的功能就是修改数据显示的格式,并进行提交后验证。在未应用该对话框之前,用户不能与对话框的父窗口以及父窗口的兄弟窗口就行交互,这样就保证了应用程序相关部分的状态不会在该对话框关闭之前改变。
可是如果我们想并不确定这一次的设置效果如何,需要多次调整设置的时候,模态对话框就显得不那么方便了。 这时候就可以利用非模态对话框,点击“应用”(apply)按钮来预览设置修改后的结果。
一般来说,模态对话框含有“接受”(accept)按钮和“拒绝”(reject)按钮;非模态对话框则含有“应用”(apply)按钮。
同样的目的,这次是非模态对话框。
import sys
from PyQt4.QtGui import *
from PyQt4.QtCore import *
class MainWindow(QWidget):
def __init__(self,parent=None):
QWidget.__init__(self,parent)
button = QPushButton("click me",self)
button.clicked.connect(self.setNumberFormat)
self.format = dict(thousandsseparator=',',decimalmarker='.',decimalplaces=2,rednegatives=True)
def setNumberFormat(self):
dialog = Intelligent(self.format,self)
self.connect(dialog,SIGNAL('changed'),self.refreshTable)
dialog.show()
def refreshTable(self):
print 1
class Intelligent(QDialog):
def __init__