Results 1 to 4 of 4

Thread: QListWidget selection custom painting problem

  1. #1
    Join Date
    Nov 2008
    Posts
    8
    Qt products
    Qt4
    Platforms
    Windows

    Default QListWidget selection custom painting problem

    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:aint ( 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:isplayRole).toString();
    painter->drawText(QPoint(option.rect.left()+5,option.rect. top()+15),index.model()->data(index,Qt:isplayRole).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);
    }

  2. #2
    Join Date
    Nov 2008
    Posts
    3
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: QListWidget selection custom painting problem

    Try call the function viewport()->repaint();

  3. #3
    Join Date
    Nov 2008
    Posts
    8
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: QListWidget selection custom painting problem

    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

  4. #4
    Join Date
    Nov 2008
    Posts
    8
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: QListWidget selection custom painting problem

    what is strange during paint method option.rect gives correct size. The problem is that on the sreen selected item is diplaying 30px height

Similar Threads

  1. custom painting in QListWidget
    By Andrew in forum Qt Programming
    Replies: 21
    Last Post: 30th March 2007, 13:16
  2. Replies: 16
    Last Post: 7th March 2006, 15:57

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.