PyQt基本对话框--表格的应用

 

# -*- coding: utf-8 -*-
from PyQt4.QtGui import *
from PyQt4.QtCore import *
import sys
import copy

QTextCodec.setCodecForTr(QTextCodec.codecForName("utf8"))
 
class MyTable(QTableWidget):
    def __init__(self,parent=None):
        super(MyTable,self).__init__(parent)
        
        self.setWindowTitle(self.tr("Table")) 
        self.resize(600,325)
        
        self.setColumnCount(5)
        self.setRowCount(6)
        
        strList=QStringList()  
        strList.append(self.tr("Sex"))  
        strList.append(self.tr("Name"))  
        strList.append(self.tr("Birthday"))
        strList.append(self.tr("Work"))
        strList.append(self.tr("Income"))
        self.setHorizontalHeaderLabels(strList)
        
        # self.Sex = ["Male", "Female"]
        # self.Work = ["worker", "Soldier", "Teacher", "Doctor", "Lawyer"]
        self.setRowData(0, 0, self.tr("爱的呼唤"), 0, 5500) 
        
    def setRowData(self, row, sex, name, work, income):
    
        pLabelSex = QLabel()
        if 0 == sex:
            pLabelSex.setPixmap(QPixmap("image/Male.png"))
        else:
            pLabelSex.setPixmap(QPixmap("image/Female.png"))
        self.setCellWidget(row, 0, pLabelSex)
        self.setColumnWidth(0, 48)
        pTWItem = QTableWidgetItem(name)
        self.setItem(row, 1, pTWItem)
        pDTE = QDateTimeEdit()
        pDTE.setDateTime(QDateTime.currentDateTime())
        pDTE.setDisplayFormat("yyyy-MM-dd")
        
        # pDTE.setCalendarPopup(True)
        self.setCellWidget(row, 2, pDTE)
        self.setColumnWidth(2,120)
        pCB = QComboBox()
        pCB.addItem(self.tr("Worker"))
        pCB.addItem(self.tr("Farmer"))
        pCB.addItem(self.tr("Doctor"))
        pCB.addItem(self.tr("Lawyer"))
        pCB.addItem(self.tr("Soldier"))
        pCB.addItem(self.tr("Teacher"))
        pCB.setCurrentIndex(work)
        self.setCellWidget(row, 3, pCB)
        pSB = QSpinBox()
        pSB.setMaximum(20000)
        pSB.setValue(income)
        self.setCellWidget(row, 4, pSB)
    
app=QApplication(sys.argv)
myqq=MyTable()
myqq.setWindowTitle("My Table")
myqq.show()
app.exec_()

 


参考:

http://blog.csdn.net/chumpklutz/article/details/6056327 

http://blog.csdn.net/lxj521/article/details/6423867

你可能感兴趣的:(PyQt)