PDA

View Full Version : QList and QTreeWidgetItem??



darpan
30th October 2006, 14:00
Hi,
Previously i am working on QT3 and using QPtrList and now i am working on QT4 and trying to use QList in place of QPtrList.

(1)
I declared the list as:
QList<TREEITEM*>list; /TREEITEM is a class

I am appending items to this list as:
treeitem=new TREEITEM((void*)MyEntry,bFileName);
list.append(treeitem); //Item added to list


Now i want to iterate this created list
In QPtrlist i am using following:
for(treeitem=list.first();treeitem;treeitem=list.n ext())

but in QList next() is not available. Many times i have to iterate the list.

How i can iterate the list.

(2)
I am inserting checkable items in QTreeWidget and also setting icon for item in first column.

But my problem is that check box and icon have space in between how i can minimize this space. I am using following code for this:-

GlobalTreeWidgetItem = new QTreeWidgetItem(treeWidget);

GlobalTreeWidgetItem->setFlags(Qt::ItemIsSelectable | Qt::ItemIsEnabled | Qt::ItemIsUserCheckable );
GlobalTreeWidgetItem->setText(0,(const char*)"Root");
GlobalTreeWidgetItem->setCheckState (0, Qt::Unchecked );
GlobalTreeWidgetItem->setIcon ( 0, Folder );


Thanks and Regards

high_flyer
30th October 2006, 14:47
There are several ways to iterate through QList.
I usually do:


QList<type>::iterator it;
for(it = mylist.begin(); it!= mylist.end(); ++it)
{
//do something
}

Which by the way is very STL like.

but in QList next() is not available. Many times i have to iterate the list.
Well, just reads the QList docs to see what IS available instead.