标签:
from PyQt4.QtCore import *
from PyQt4.QtGui import *
from PyQt4.Qt import *
import sys
from aa1 import Ui_Form
class BB(QWidget,Ui_Form):
def __init__(self):
super(BB,self).__init__()
self.setupUi(self)
self.addedit.setItem(0,0,QTableWidgetItem(‘aa‘))
self.addedit.setColumnCount(1)
self.addurl.returnPressed.connect(self.tt1)
def bb1(self,row,col):
if self.addedit.item(row,col)==None or self.addedit.item(row,col)and self.addedit.item(row,col).text()==‘‘:
print ‘ok‘
else:
print ‘error‘
def tt1(self):
text=self.addurl.text()
if text.isEmpty():
QMessageBox.information(self,u‘错误‘,u‘文本框无法为空‘)
else:
self.crea1()
def crea1(self):
tab=self.addedit.rowCount()
col=self.addedit.columnCount()
self.addedit.insertRow(tab)
text=self.addurl.text()
item=QTableWidgetItem(text)
self.addedit.setItem(tab,0,item)
for row in xrange(tab):
for col1 in xrange(col):
item=self.addedit.item(row,col1)
if item and item.data(Qt.DisplayRole)==text:
#self.addedit.item(row,col1).setSelected(True)
self.addedit.setRowCount(tab)
QMessageBox.information(self,u‘错误‘,u‘当前文本{0}存在了‘.format(text))
#print dir(self.addedit.indexFromItem(item).model())
return self.addedit.indexFromItem(item)
return None
app=QApplication([])
bnb=BB()
bnb.show()
sys.exit(app.exec_())
效果如下:
对我帮助的链接地址如下:http://stackoverflow.com/questions/11898382/pyqt-search-item-qtablewidget-and-take-its-coordinates
标签:
原文地址:http://www.cnblogs.com/mhxy13867806343/p/5018171.html