Setting the value of one cell in QTableWidget fills everything.
I've just started PyQt programming and I've run into this little
problem. When I set the text of one cell in my table, all the other
cells fill with that value.
All I wanted to do was run a loop, printing in each cell the row and
column number.
Here's the code.
--
from PyQt4 import QtGui,QtCore
import sys
class mywindow(QtGui.QWidget):
def __init__(self,parent=None):
QtGui.QWidget.__init__(self,parent)
self.resize(700,700)
self.mytable=QtGui.QTableWidget(7,6,self)
self.mytable.resize(700,700)
def filltable(self):
items=QtGui.QTableWidgetItem()
for column in range(self.mytable.columnCount()):
for row in range(self.mytable.rowCount()):
items.setText("row: " + str(row) + " column: " +
str(column))
self.mytable.setItem(row,column,items)
app=QtGui.QApplication(sys.argv)
mainwin=mywindow()
mainwin.filltable()
qb.show()
app.exec_()
--
http://mail.python.org/mailman/listinfo/python-list
How do I sort items in a tableview without a column being selected?
I have this TableView, which is sorted by column when the user clicks
on the header. The problem is though, that all the items are selected
and nothing gets sorted. But if the window loses focus everything's
get's sorted.
Basically I have list of tags say,
[{"artist":"Artist1","title":Title1"} , {"artist":"Artist2" , "title":
"Title2"}] etc. Where each tag is listed in a column. Then I sort them
and reset. Here's the code:
def sort(self,column,order=Qt.DescendingOrder):
tag=self.headerdata.text
newdic={}
li=[]
i=0
for z in self.taginfo: #taginfo has all the tags
if not newdic.has_key(z[tag]):
newdic[z[tag]]=z
li.append(z[tag])
else:
newdic[z[tag] + str(i)]=z
li.append(z[tag] + str(i))
i+=1
li.sort()
self.taginfo=[newdic[z] for z in li]
self.reset()
Any ideas?
--
http://mail.python.org/mailman/listinfo/python-list
Re: Setting the value of one cell in QTableWidget fills everything.
> Move the creation of the QTableWidgetItem() to the inner loop (and call > it "item" rather than "items"). > > Phil Thanks, that works perfectly. -- http://mail.python.org/mailman/listinfo/python-list
