PDA

View Full Version : ListWidget positions item



talex
18th October 2008, 12:21
Hello. I'm new to this forum and also to qt. I need some help with these. I use Qt 4.3.4 wint MinGW. I made a window which contain a QListWidget. I made a combobox from wich i add item to ListWidget wiht text and icon.I can move items in ListWidget where i want. I save the ListWidget saving the text item , icon item and the position item (row and column).
The problem i have i that i made a function to load the item to list and put them to the position that were saved. I read in help and i found up that to insert a item to ListWidget to a certain posistion in list (where i want) i must user QListView::setPositionForIndex(QPoint &point,const QModelIndex &index) cont.
to retreive the QModelIndex from QListWidgetItem i must use QListWidget::indexFromItem(QListWidgetItem *item) const..... both this function are protected. my problem is that i can't use them. i tried a lot of posibilities and nothig.
Can someone help me? and tel my how i can use these functions togheter and insert the item at position that i want? Or if can tell me another way to insert intems into QListWidget at given position.. i mentioned that i have the position....

thanks a lot

spirit
18th October 2008, 13:19
why you can't use this method


void QListWidget::insertItem ( int row, QListWidgetItem * item )
Inserts the item at the position in the list given by row.

?

talex
18th October 2008, 15:01
I use this function initialy to add items to list,but function add an item to a specific row not to specific position (row and column) in list. My listWdiget is in Icon mode so i can set an item every where i wish . I search on net and i found just one example to add an item to a QListWidget at specified coordonites. they use in example a derrived class of QListWidget in whicjh they use to add items to list using this function:
QListView::setPositionForIndex(QPoint &point,const QModelIndex &index).

I compile the example and it works.I put the listWidget in designer and try to use same function above and i get error that :
1. i can't use listWidget->indexFromItem(QListWidgetItem *item) because is protected
2. so with setPositionForIndex
the compiler tells me that i can't use this function...i try to create a derivate class based on QListWidget an promote la listWidget from to designer to this classs...and nothig happens same message..:( I wander if there is another method to insert item to list to a specified coordonates.

thanks

talex
21st October 2008, 16:16
I succed to use setPositionForIndex() to insert an intem to a specific position.the problem is that when i insert a second item tha first item is moved to 0,0 and last item remains at specific position.Mean always i insert a intem previous items lose their position and the last doesn't.i understan is about repaint() function...is any way to make previous items remain at their position while i insert a new item to the list?

please help:D


Thanks a lot.