PDA

View Full Version : Size of an Icon



LordQt
24th August 2007, 14:14
Hello Friends.
How can I modify the size of my icon in my QListWidgetItem. I have an png with 128*128



QStringList myStringList2;
myStringList2 <<"test";
QIcon testItemIcon(":/images/undo.png");
foreach(QString str2, myStringList2){
QListWidgetItem *testItem = new QListWidgetItem(testItemIcon, str2, customerList);
customerList->addItem(testItem);
QRadialGradient gradient(100, 100, 100, 100, 100);
gradient.setColorAt(0, QColor::fromRgbF(210, 239, 109,0));
gradient.setColorAt(1, QColor::fromRgbF(0, 1, 0, 0));
QBrush brush(gradient);
testItem->setBackground(brush);
}

but my icon is quit little and i don´t know why??

Have you some ideas

jpn
24th August 2007, 14:20
QListWidget is a QListView. QListView is a QAbstractItemView. QAbstractItemView has a property iconSize (http://http://doc.trolltech.com/latest/qabstractitemview.html#iconSize-prop):

listWidget->setIconSize(QSize(24, 24));

LordQt
24th August 2007, 14:27
I don´t understand i don´t have a listWidget i have a ListWidgetItem

and QListWidgetItem have no setIconSize()

marcel
24th August 2007, 14:44
QAbstractItemView is the base class of QListWidget and it has that method.

Regards

jpn
24th August 2007, 14:47
QListWidget is a widget where QListWidgetItems are added to. QListWidgetItems are nothing visible until they are added to a QListWidget.

So what is customerList?




customerList->addItem(testItem);

LordQt
26th August 2007, 00:01
thank you it rocks ;o)))

it seems that every beginning is hard but there is a light i can see it ;o)) thanks for ya help friends

iw2nhl
26th August 2007, 13:40
QListWidgetItem *testItem = new QListWidgetItem(testItemIcon, str2, customerList);
customerList->addItem(testItem);


Hi,
only a little note: it is not needed to use addItem() if you already specified the parent QListWidget in the QListWidgetItem constructor.
It is not an error, but it is redundant.

These are a little better ways to do it:


// Constructed with the list widget as their parent widget
QListWidgetItem *testItem = new QListWidgetItem(testItemIcon, str2, customerList);



// Constructed with no parent widget and added to the list later
QListWidgetItem *testItem = new QListWidgetItem(testItemIcon, str2);
customerList->addItem(testItem);


References:
QListWidget : http://doc.trolltech.com/4.3/qlistwidget.html#details
QListWidgetItem : http://doc.trolltech.com/4.3/qlistwidgetitem.html#QListWidgetItem-3

LordQt
26th August 2007, 21:36
jes it´s logic thank you for your tip