qt下面例子学习(部分功能)

from aa import Ui_Form
from PyQt4.Qt import *
from PyQt4.QtCore import *
from PyQt4.QtGui import *
from sys import *
class A(QWidget,Ui_Form):
    def __init__(self):
        super(A,self).__init__()
        self.setupUi(self)
        self.Button.clicked.connect(self.aaa)
        self.Box.stateChanged.connect(self.selectaa)
        #self.Button.installEventFilter(self)
        self.Button.setCheckable(True)
    def eventFilter(self,watched,event):
        if watched == self.Button:
            if event.type() == QEvent.MouseButtonPress:
                mouseEvent = QMouseEvent(event)
                if mouseEvent.buttons() == Qt.LeftButton:
                    print 'left'

                else:
                    print 'about'

        return QWidget.eventFilter(self,watched,event)
    def aaa(self):
        text=self.Edit.text()
        row1=self.table1.rowCount()
        self.table1.insertRow(row1)
        item=QTableWidgetItem(text)
        # item.setTextAlignment(Qt.AlignLeft|Qt.AlignCenter)
        # item.setBackgroundColor(Qt.red)
        try:
            self.table1.setItem(row1,0,item)
            self.Box.setCheckState(Qt.Unchecked)
            self.table1.item(row1,0).setCheckState(Qt.Unchecked)
            if text.isEmpty():
                self.table1.setRowCount(row1)
                self.table1.item(row1,0).setData(10,QVariant())
            for i in range(row1):
                if self.table1.item(i,0).isSelected()!=False:
                    self.table1.item(i,0).setCheckState(Qt.Checked)
        except:
            QMessageBox.information(self,u'警告',u'edit或者表格中为空')
    def selectaa(self):
        box=self.Box.isChecked()
        row=self.table1.rowCount()
        col=self.table1.columnCount()
        for i in range(row):
            for j in range(col):
                if self.table1.item(i,0):
                    if box:
                        self.table1.item(i,0).setSelected(True)
                        self.table1.item(i,0).setCheckState(Qt.Checked)
                    else:
                        self.table1.item(i,0).setCheckState(Qt.Unchecked)
app=QApplication([])
a=A()
a.show()
exit(app.exec_())

下面是截图

qt下面例子学习(部分功能)_第1张图片

你可能感兴趣的:(qt下面例子学习(部分功能))