View Full Version : QTableView icons
radu_d
16th October 2007, 20:59
Is there a way in which I could display an icon to a row in QTableView? I want to put an icon like I put to the QTableWidgetItem. The icon to be in the same cell with the text. Is that possible?
Thank you.
Tux-Slack
16th October 2007, 21:24
Sure it's posible.
http://doc.trolltech.com/4.3/qtablewidgetitem.html#setIcon
radu_d
16th October 2007, 21:26
I want to set items icons in QTableView not QtableWidget :) Do you know how I can do that?
Tux-Slack
16th October 2007, 21:40
Sorry, missunderstood your sentence.
I do it like so:
QModelIndex pI;
model->insertRow(itemCount, QModelIndex());
pI = model->index(itemCount,0,QModelIndex());
model->setData( pI, title, Qt::DisplayRole);
model->item(itemCount, 0)->setEditable( false );
// Lot's of adding item+subitems code
pI = model->index(itemCount,0,QModelIndex());
icon = setItemIcon(type, ownership);
model->setData( pI, QIcon( icon ), Qt::DecorationRole );
setItemIcon() function is my own function in which I programaticaly choose which icon to use, and icon is a QString variable which contains strings like, ":/images/some_icon.xpm"
And I use QStandardItemModel for the item model. But I think this works on all items.
itemCount is the number to which row the icon should be assigned to and 0 is for the first column.
radu_d
16th October 2007, 22:02
Thanks a lot, this solved my problem :) You are great.
Powered by vBulletin® Version 4.2.5 Copyright © 2024 vBulletin Solutions Inc. All rights reserved.