Results 1 to 4 of 4

Thread: Wrong painting of Delegate

  1. #1
    Join Date
    Oct 2008
    Location
    Beijing China
    Posts
    77
    Thanks
    21
    Thanked 3 Times in 3 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Question Wrong painting of Delegate

    Hi, all, i sub class QStyledItemDelegate and re-implement the paint () function like this:
    Qt Code:
    1. void CustomDelegate::paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index)const
    2. {
    3. painter->save();
    4. painter->fillRect(option.rect, QBrush(Qt::red));
    5. painter->setPen(QColor(Qt::black));
    6. painter->drawRect(option.rect);
    7. painter->restore();
    8. QStyledItemDelegate::paint(painter, option, text, false);
    9. }
    To copy to clipboard, switch view to plain text mode 

    Sadly the delegate paint the item beyond the boder of the QListView and looks like the attachment. I don't know why. The picture in the attachment is a screen shotcut when the cursor hover the area that is very near to the list veiw's bottom border, outside the view.

    Any help and suggestions will be appreciated greatly, thank you in advance.
    Attached Images Attached Images

  2. #2
    Join Date
    Oct 2006
    Location
    New Delhi, India
    Posts
    2,467
    Thanks
    8
    Thanked 334 Times in 317 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Wrong painting of Delegate

    Try re-ordering ur steps as -
    Qt Code:
    1. painter->fillRect(option.rect, QBrush(Qt::red));
    2. QStyledItemDelegate::paint(painter, option, text, false);
    3. painter->save();
    4. painter->setPen(QColor(Qt::black));
    5. painter->drawRect(option.rect);
    6. painter->restore();
    To copy to clipboard, switch view to plain text mode 

    Am not sure if it will work, but the idea is the border rect will be on top...

  3. #3
    Join Date
    Oct 2008
    Location
    Beijing China
    Posts
    77
    Thanks
    21
    Thanked 3 Times in 3 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Wrong painting of Delegate

    Quote Originally Posted by aamer4yu View Post
    Try re-ordering ur steps as -
    Qt Code:
    1. painter->fillRect(option.rect, QBrush(Qt::red));
    2. QStyledItemDelegate::paint(painter, option, text, false);
    3. painter->save();
    4. painter->setPen(QColor(Qt::black));
    5. painter->drawRect(option.rect);
    6. painter->restore();
    To copy to clipboard, switch view to plain text mode 

    Am not sure if it will work, but the idea is the border rect will be on top...
    Thanks for your advice.

    I tried as yours and the issue remain the same. And i remove the calling of QStyledItemDelegate:aint(...) and the red area outside the view still exists.

  4. #4
    Join Date
    Oct 2008
    Location
    Beijing China
    Posts
    77
    Thanks
    21
    Thanked 3 Times in 3 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Unhappy Re: Wrong painting of Delegate

    I used QStyledItemDelegate and the issue remain! Here's my code:
    Qt Code:
    1. /* listView is a QListView*/
    2. /* set item's data before set model */
    3. for(...)
    4. {
    5. item->setText("test");
    6. item->setSizeHint(Qsize(100, 50));
    7. model->appendRow(item);
    8. }
    9. ...
    10. listView->setModel(model);//no setting delegate is called
    To copy to clipboard, switch view to plain text mode 

    and i set the style sheet as
    Qt Code:
    1. QListView::item
    2. {
    3. background-color:red;
    4. }
    To copy to clipboard, switch view to plain text mode 

    It astonished me that the issue is not solved!

    BTW, this list view is a child widget of another widget which proxyed by a QGraphicsItem. I'm currently wondering whether or not that is the reason

Similar Threads

  1. Painting a CC_ToolButton in a custom delegate
    By victor.fernandez in forum Qt Programming
    Replies: 2
    Last Post: 17th October 2008, 12:11
  2. Delegate for a certain item?
    By somebody in forum Qt Programming
    Replies: 1
    Last Post: 18th August 2008, 22:55
  3. Item Delegate Painting
    By stevey in forum Qt Programming
    Replies: 3
    Last Post: 9th May 2008, 07:37

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.