pyqt4 qTableWidget add items help

ookrin ooklah at gmail.com
Sat Apr 18 20:16:55 CEST 2009


On Apr 18, 3:46 am, Sebastian Wiesner <basti.wies... at gmx.net> wrote:
> -----BEGIN PGP SIGNED MESSAGE-----
> Hash: SHA1
>
> <ookrin – Samstag, 18. April 2009 11:58>
>
> [...]> I've been trying
>
> >         while(len(orders)> i):
> >             ui.tb1_tblOrders.setCurrentCell(i,0,orders[i][1])
> >             i+=1
>
> > which to me, says go add in the first column row with the first order,
> > and it makes sense to me
>
> Read the documentation [1] to learn, what ".setCurrentCell()" actually does
> and what its arguments are!  And please stop this wild guessing ...
>
> The method you're searching for is ".setItem()" [2], which adds a new
> QTableWidgetItem [3] to a QTableWidget.
>
> [1]http://doc.trolltech.com/4.5/qtablewidget.html#setCurrentCell
> [2]http://doc.trolltech.com/4.5/qtablewidget.html#setItem
> [3]http://doc.trolltech.com/4.5/qtablewidgetitem.html
>
> - --
> Freedom is always the freedom of dissenters.
>                                       (Rosa Luxemburg)
> -----BEGIN PGP SIGNATURE-----
> Version: GnuPG v2.0.11 (GNU/Linux)
>
> iEYEARECAAYFAknpr4sACgkQGV4vxEMMOxdnawCfTXO55EffBJMQ7h91RGtMIpZ/
> hcYAoLQ9yF5u/hBgNRvqxGRlIy5lPDgb
> =Q6ef
> -----END PGP SIGNATURE-----

I forgot to include what I tried first.
setCurrentItem was just the last thing I was on at the time.

First I filled out a row in Designer to see how it loads the items. It
loads like this:
self.tb1_tblOrders.item(0, 0).setText(QtGui.QApplication.translate
("MainWin", "Date", None, QtGui.QApplication.UnicodeUTF8))

Ok following that example:

ui.tb1_tblOrders.item(0,0).setText(QtGui.QApplication.translate
("MainWindow",order[0][1], None,QtGui.QApplication.UnicodeUTF8))

AttributeError: 'NoneType' object has no attribute 'setText'

So reading through the QTableWidget Doc I see the setItem

setItem(int,int, QTableWidgetItem * item)
QTableWidgetItem*item ???

The only example on the entire page:

     QTableWidgetItem *newItem = new QTableWidgetItem(tr("%1").arg(
         pow(row, column+1)));

is that setup as c++ ? Ok, it's a class.

twi = QTableWidgetItem()
 newItem = twi(order[i][0])
ui.tb1_tb1Orders.setItem(i,0,newItem)

NameError: global name 'QTableWidgetItem' is not defined

At the top of the page
include <QTableWidgetItem>
from PyQt4 import  ?? QtGui? QtCore? Those are already loaded   other
options are pyqtconfig and uic and those don't sound correct...

And that's what I did first. Then I started guessing in the next
logical order, not wildly. editItem, setCurrentItem, setCurrentCell.
Then I came here. So I guess I actually stuck at the QTableWidgetItem
thing, I should have made that a little more clearer first post.

Andrew



More information about the Python-list mailing list