# coding=utf-8
from PyQt4.QtGui import *
from PyQt4.QtCore import *
from MyTableWidget import MyTableWidget
from MyQThread import MyQThread
import sys
class MyQMainWindow(QMainWindow):
def __init__(self, parent=None):
super(MyQMainWindow, self).__init__(parent)
mycode = 'utf-8'
code = QTextCodec.codecForName(mycode)
QTextCodec.setCodecForLocale(code)
QTextCodec.setCodecForTr(code)
QTextCodec.setCodecForCStrings(code)
self.initMenu()
self.MyTable = MyTableWidget(0, 8)
print type(self.MyTable)
s = "松鼠"
a = QWidget()
self.thread = MyQThread()
v_tablebox = QVBoxLayout()
v_tablebox.addWidget(self.MyTable)
print s
# newItem = QTableWidgetItem(s)
# self.MyTable.setItem(0, 0, newItem)
#
# newItem = QTableWidgetItem("10cm")
# self.MyTable.setItem(0, 1, newItem)
#
# newItem = QTableWidgetItem("60g")
# self.MyTable.setItem(0, 2, newItem)
self.btnStart = QPushButton('Start')
v_tablebox.addWidget(self.btnStart)
h_box = QHBoxLayout()
h_box.addLayout(v_tablebox)
a.setLayout(h_box)
# g_box = QGridLayout()
# g_box.addLayout(h_box,0,0,0,0)
# self.setLayout(h_box)
self.setCentralWidget(a)
self.resize(QSize(800, 300))
self.setWindowTitle(u'水果')
self.row = 1
self.connect(self.btnStart, SIGNAL('clicked()'), self.slotStart)
self.connect(self.thread, SIGNAL('output(QString)'), self.slotAdd)
def slotAdd(self, file_inf):
self.row = self.MyTable.rowCount()
self.MyTable.insertRow(self.row)
newItem = QTableWidgetItem('jianpan')
self.MyTable.setItem(self.row, 0, newItem)
newItem1 = QTableWidgetItem("10cm")
self.MyTable.setItem(self.row, 1, newItem1)
newItem2 = QTableWidgetItem("60g")
self.MyTable.setItem(self.row, 2, newItem2)
self.row = self.row + 1
def slotStart(self):
self.btnStart.setEnabled(False)
self.thread.start()
def initMenu(self):
exitAction = QAction(QIcon('exit.png'), '&Exit', self)
exitAction.setStatusTip('Exit application')
exitAction.triggered.connect(QApplication.quit)
self.statusBar()
menubar = self.menuBar()
fileMenu = menubar.addMenu('&File')
fileMenu.addAction(exitAction)
if __name__ == "__main__":
app = QApplication(sys.argv)
myWindow = MyQMainWindow()
myWindow.show()
sys.exit(app.exec_())
转载于:https://www.cnblogs.com/jian-pan/p/6616976.html