PDA

View Full Version : QListView



moowy
2nd October 2006, 13:51
Hello,

I habe a problem with a qlistview. I have several items in it, but when i delete them i want to display text:"no items in listview" but i don't know how to do this. Any ideas?? The problem is that i don't know how to display the text (how?) ?

I need something equivalent to this-> void Q3Canvas::setBackgroundPixmap ( const QPixmap & p ) [virtual]

jpn
2nd October 2006, 14:02
You could for example override list view's paint event and draw the text by hand in case there is no items.



void MyListView::paintEvent(QPaintEvent* event)
{
QListView::paintEvent(event); // let the list view draw itself as it would

// special case when there is no items
if (model()->rowCount() == 0)
{
QPainter p(viewport());
p.drawText(rect(), Qt::AlignCenter, "No items..");
}
}

Not sure if it works as desired or if it even compiles, but it should give you an idea..

moowy
2nd October 2006, 14:14
It works. Thanks :) (if you're wondering: u're code compiles perfectly without modifications)