PDA

View Full Version : Insert an item in an horizontal QListWidget



satoshi
14th May 2009, 09:22
Hi,
How can I insert an item in an horizontal QListWidget in a specified position?

Thank you! Dario

aamer4yu
14th May 2009, 09:29
What do you mean by horizontal QListWidget ??
I guess you mean multiple column in one row...
If yes, have a look at QTableWidget or QTreeWidget instead

satoshi
14th May 2009, 10:17
I meant this:

http://www.satoshi.ch/warez/thumbsList.jpg

Code:

G2_ThumbsList::G2_ThumbsList(QWidget *parent, unsigned int iconWidth, unsigned int iconHeight) : QListWidget(parent)
{
this->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Ignored);
this->setFixedHeight(116);
this->setHorizontalScrollMode(QAbstractItemView::ScrollP erPixel);
this->setMovement(QListView::Static);
this->setGridSize(QSize(126, 116));
this->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff) ;
this->setThumbsSize(iconWidth, iconHeight);
this->setViewMode(QListView::IconMode);
this->setWrapping(false);
}

void G2_ThumbsList::addThumb(G2_Thumb *thumb)
{
this->addItem(thumb);
}

void G2_ThumbsList::insertThumb(G2_Thumb *thumb, unsigned int position)
{
if(position < this->count())
{
// HERE...?
}
else
{
this->addItem(thumb);
}
}


(Note: G2_Thumb inherits QListWidgetItem)

I think that QTableWidget and QTreeWidget don't suite my situation..

Thank you! Dario

satoshi
18th May 2009, 11:34
up...... :(

Lykurg
18th May 2009, 12:27
QListWidget::insertItem ( int row, QListWidgetItem * item )?

aamer4yu
18th May 2009, 13:21
I think that QTableWidget and QTreeWidget don't suite my situation..
Right. After seeing the pic u posted, it is clear you just need a simple QListWidget.
Lykurg already gave the solution :)

satoshi
19th May 2009, 08:26
QListWidget::insertItem ( int row, QListWidgetItem * item )?


Right. After seeing the pic u posted, it is clear you just need a simple QListWidget.
Lykurg already gave the solution :)

I already tried this solution but it doesn't work :( I think there is a problem because QListWidget is for a vertical list.. the first parameter of insertItem is "int row", if I specify a column it doesn't work..

satoshi
19th May 2009, 08:33
Sorry, it works :D The problem wasn't this....

Thank you!

aamer4yu
19th May 2009, 17:33
Could you post what was the problem, and how it got cleared ?
May be it will help someone someday