PDA

View Full Version : QListWidget selection custom painting problem



xeento
27th November 2008, 09:26
Hi everyone,

I'm using QListWiget with custom itemdelegate for painting items.
The thing is that i want to show selected item in diffrent size than others.
For example if all unselected items have 30px height i want to set height of selected item to 60px. I've implemented sizeHint and paint method. Everything works fine except this that after when selection is changing listwidget doesn't refrest itself. After resizing main application window selected item is displaying as it should.

My question is how to force QListWidget to redraw itself when selection is changed.

Thank a lot, I'm going mad with this issue so please help.


void QContactItemDelegate::paint ( QPainter * painter, const QStyleOptionViewItem & option, const QModelIndex & index ) const
{


painter->save();
painter->fillRect(option.rect,option.palette.brightText());
int sz;
sz = option.rect.height();
if (option.state & QStyle::State_Selected)
{
painter->fillRect(option.rect,option.palette.highlight());
}

QString nnn;
nnn = index.model()->data(index,Qt::DisplayRole).toString();
painter->drawText(QPoint(option.rect.left()+5,option.rect.t op()+15),index.model()->data(index,Qt::DisplayRole).toString());
painter->restore();
}

QSize QContactItemDelegate::sizeHint ( const QStyleOptionViewItem & option, const QModelIndex & index ) const
{
if (qobject_cast<QListView *>(parent()) != 0) {
QListView *v = qobject_cast<QListView*>(parent());
int indx,rrr;
indx = -1;
if(v->selectionModel()->selectedIndexes().size()>0)
{
indx = v->selectionModel()->selectedIndexes().at(0).row();
rrr = index.row();
if(indx == rrr)
{
return QSize(option.rect.width(),60);
}
}

}

return QSize(option.rect.width(),20);
}

jasplye
27th November 2008, 09:32
Try call the function viewport()->repaint();

xeento
27th November 2008, 09:47
I've connected signal itemselectionchanged and i've called vieport()->repaint but unfortunatelly with no luck :( selected item still is 30px height and should be 60 :(

xeento
27th November 2008, 09:49
what is strange during paint method option.rect gives correct size. The problem is that on the sreen selected item is diplaying 30px height :(