[Qt-interest] How to get the column of a certain HeaderItem from QTableWidget?

Pedro Santos nonspam2048 at yahoo.de
Wed May 12 15:19:28 CEST 2010


Hi,
I try to find the position of a certain HeaderItem of QTableWidget in order to 
be able to change the position of the table header and insert new items at the 
right position anyway.

I tryed the following in the constructor of my derived QTableWidget I wrote:

     _headerArticle = new QTableWidgetItem(tr("Article"));
     _headerTitle = new QTableWidgetItem(tr("Title"));
	[...] //some more code

     setHorizontalHeaderItem(0,_headerArticle);
     setHorizontalHeaderItem(1,_headerTitle);
     	[...] //some more code

     horizontalHeader()->setMovable(true);

Then I have to insert items in the right column, I tryed to get the current 
column of the the following way, but the position is every time returned as -1 
which means the item isn't in the table:


     QString title =  article->getTitle();
     QString condition =  article->getCondition();
     	[...]

     QTableWidgetItem* itemTitle = new QTableWidgetItem(title);
     QTableWidgetItem* itemCondition = new QTableWidgetItem(condition);

     int row = rowCount();
     insertRow(row);

I tryed this two methods:

     setItem(row, _headerTitle->column(), itemTitle); // returns -1
     setItem(row, _headerCondition->column(), itemCondition); // returns -1

So whats wrong with that code and how can I get the column number of my HeaderItem?

Regards
Pedro Santos



More information about the Qt-interest-old mailing list