PDA

View Full Version : KLed in a list view



villy
9th August 2006, 09:21
Hi
Is it possible to put a generic QWidget into a Column of QListViewItem?

I want a list view where each item is composed by two colimn: a string and a KLed. I have thought to use a pixmap, but if I could use KLed is better :). Some Idea?

Thanks

e8johan
9th August 2006, 11:43
I would say that it cannot be done easily. A pixmap would be the most straight forward method, also sub-classing QListViewItem is a possibility.

hayati
9th August 2006, 12:30
qlistviewitem does not support adding widgets in it. Rather you may override its paintEvent method. Within paintEvent method you could draw your own widgets. if you look into qt's source files they did similar to build a list view item with check box support. But pixmap is easier than all.

villy
9th August 2006, 12:48
Tanks a lot! ;)
I thought that it wasn't so easy to do without pixmap...

hayati
9th August 2006, 13:05
it's not as much hard. i'll post you a progress bar within listviewitems.

you need to subclass listviewitem.
overriding of paintCell method is enough i thing.

assume that SomeListViewItem is subclass of QListViewItem

void SomeListViewItem::paintCell( QPainter *p, const QColorGroup &cg,
int column, int w, int alignment )
{
QListViewItem::paintCell( p, cg, column, w, alignment );

QColor gray(223, 221, 244);
QColor white(255, 255, 255);
QColor textColor(255, 0, 0);

double wGray = (double)m_iSinyalSeviyesi * w / 100;
double wWhite = (double)w - wGray;

// draw for column number 3 only
// let listview draw for other columns
if (column == 3) {
p->setBrush(gray);
p->drawRect(0, 5, (int)wGray, 32);
p->setBrush(white);
p->drawRect(wGray, 5, (int)wWhite, 32);
p->setPen(textColor);
p->drawText(w/2-10, height()/2+5, QString(s));
}
}

jacek
9th August 2006, 13:31
i'll post you a progress bar within listviewitems.
For a pixmap all you need is QListViewItem::setPixmap().

villy
10th August 2006, 13:23
thanks hayati! You've given me a very good example ;)

Now I try to do it :).

Thanks a lot!