实例2 标准对话框的使用
from PyQt4.QtCore import *
from PyQt4.QtGui import *
import sys
class StandardDialog(QDialog):
def __init__(self,parent = None):
super(StandardDialog,self).__init__(parent)
self.filePushButton = QPushButton("File Dialog")
self.fileLineEdit = QLineEdit()
self.fileLineEdit.setText("Hello")
self.colorPushButton = QPushButton("Color Dialog")
self.colorFrame = QFrame()
self.colorFrame.setFrameShape(QFrame.Box)
self.colorFrame.setAutoFillBackground(True)
self.fontPushButton = QPushButton("Font Dialog")
self.fontLineEdit = QLineEdit()
self.fontLineEdit.setText("Font Dialog")
gridlayout = QGridLayout()
gridlayout.addWidget(self.filePushButton,0,0)
gridlayout.addWidget(self.fileLineEdit,0,1)
gridlayout.addWidget(self.colorPushButton,1,0)
gridlayout.addWidget(self.colorFrame,1,1)
gridlayout.addWidget(self.fontPushButton,2,0)
gridlayout.addWidget(self.fontLineEdit,2,1)
self.connect(self.filePushButton,SIGNAL("clicked()"),self.openFileDialog)
self.connect(self.colorPushButton, SIGNAL("clicked()"),self.openColorDialog)
self.connect(self.fontPushButton, SIGNAL("clicked()"),self.openFontDialog)
self.setLayout(gridlayout)
def openFileDialog(self):
s = QFileDialog.getOpenFileName(None, "open file dialog")
self.fileLineEdit.setText(s)
def openColorDialog(self):
color = QColorDialog.getColor(Qt.blue)
self.colorFrame.setPalette(QPalette(color))
def openFontDialog(self):
font,ok = QFontDialog.getFont()
self.fontLineEdit.setFont(font)
if __name__ == '__main__':
app = QApplication(sys.argv)
sd = StandardDialog()
sd.show()
app.exec_()