日期:2014-05-16  浏览次数:20758 次

Linux窗口程序设计 Qt4精彩实例分析 pyqt实现

位置函数

?

from PyQt4.QtCore import *
from PyQt4.QtGui import *
import sys

class Geometry(QDialog):
    def __init__(self,parent = None):

        super(Geometry,self).__init__(parent)
        
        self.labelx             = QLabel("x: ")
        self.labely             = QLabel("y: ")
        self.labelframeGeometry = QLabel("frameGeometry : ")
        self.labelpos           = QLabel("pos : ")
        self.labelwidth         = QLabel("width : ")
        self.labelheight        = QLabel("height : ")
        self.labelrect          = QLabel("rect : ")
        self.labelsize          = QLabel("size : ")
        
        self.xlabel             = QLabel()
        self.ylabel             = QLabel()
        self.frameGeometrylabel = QLabel()
        self.poslabel           = QLabel()
        self.widthlabel         = QLabel()
        self.heigthlabel        = QLabel()
        self.rectlabel          = QLabel()
        self.sizelabel          = QLabel()
        
        self.layout             = QGridLayout()
        self.layout.addWidget(self.labelx,0,0)
        self.layout.addWidget(self.xlabel,0,1)
        self.layout.addWidget(self.labely,1,0)
        self.layout.addWidget(self.ylabel,1,1)
        self.layout.addWidget(self.labelwidth,2,0)
        self.layout.addWidget(self.widthlabel,2,1)
        self.layout.addWidget(self.labelrect,3,0)
        self.layout.addWidget(self.rectlabel,3,1)
        self.layout.addWidget(self.labelsize,4,0)
        self.layout.addWidget(self.sizelabel,4,1)
        self.layout.addWidget(self.labelframeGeometry,5,0)
        self.layout.addWidget(self.frameGeometrylabel,5,1)
        self.layout.addWidget(self.labelheight,6,0)
        self.layout.addWidget(self.heigthlabel,6,1)
        self.layout.addWidget(self.labelpos,7,0)
        self.layout.addWidget(self.poslabel,7,1)
        
        self.setLayout(self.layout)
        self.setWindowTitle("geometry")
    def updateLabel(self):
        temp = QString()
        self.xlabel.setText(temp.setNum(self.x()))
        self.ylabel.setText(temp.setNum(self.y()))
        
        r = temp.setNum(self.rect().x()) + ","+temp.setNum(self.rect().y()) \
                          +","+temp.setNum(self.rect().width())+","+temp.setNum(self.rect().height()) 
        self.rectlabel.setText(r)
    
    def moveEvent(self,event):
        self.updateLabel()
    def resizeEvent(self,event):
        self.updateLabel()
        
        
        
        
if __name__ == '__main__':
    app = QApplication(sys.argv)
    sd = Geometry()
    sd.show()
    app.exec_()

?

?

?

标准对话框的使用

?

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()")