码迷,mamicode.com
首页 > 其他好文 > 详细

qt tablewidget搜索效果如下

时间:2015-12-04 06:26:21      阅读:252      评论:0      收藏:0      [点我收藏+]

标签:

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

qt tablewidget搜索效果如下

标签:

原文地址:http://www.cnblogs.com/mhxy13867806343/p/5018171.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!