Results 1 to 4 of 4

Thread: Delegate and Stylesheet

  1. #1
    Join Date
    Jul 2010
    Posts
    16
    Qt products
    Qt Jambi
    Platforms
    Unix/X11 Symbian S60 Maemo/MeeGo

    Default Delegate and Stylesheet

    Hi,

    I have a stylesheet for a QListView which is linked to a QStyledItemDelegate in order to paint item in a custom way.

    I have a problem when adding some style for the items:

    String style = "QListView {background: url(" + GlobalConstants.IMAGE_PATH + "background.png); }";
    style += " QListView::item { color: white; }";
    style += " QListView::item:hover { color: red; }";

    The QListView style works fine but the QListView::item style does not appear.
    I've tried to unlink the QStyledItemDelegate and the item style did work!

    So my question is, how can we set style for the list items when using a delegate?

    Thanks.

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

    Default Re: Delegate and Stylesheet

    How are you painting in your custom item delegate ?

    I dont think you are using QStyle functions to draw...

  3. #3
    Join Date
    Jul 2010
    Posts
    53
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows
    Thanks
    1

    Default Re: Delegate and Stylesheet

    here one technique using QLabel as content renderer

    Qt Code:
    1. void SomeItemDelegate::paint(QPainter *painter,
    2. const QStyleOptionViewItem &option,
    3. const QModelIndex &index) const
    4. {
    5. QLabel renderer;
    6. renderer.setStyleSheet(getStyleSheet(index));
    7. renderer.setText(makeDisplayString(index));
    8. renderer.resize(option.rect.size());
    9. painter->save();
    10. painter->translate(option.rect.topLeft());
    11. renderer.render(painter);
    12. painter->restore();
    13. }
    To copy to clipboard, switch view to plain text mode 

  4. #4
    Join Date
    Jul 2010
    Posts
    16
    Qt products
    Qt Jambi
    Platforms
    Unix/X11 Symbian S60 Maemo/MeeGo

    Default Re: Delegate and Stylesheet

    Thanks, this helped me a lot!

Similar Threads

  1. Need help with my delegate
    By Guilo in forum Qt Programming
    Replies: 6
    Last Post: 1st July 2010, 12:15
  2. Is delegate necessary here?
    By scythe in forum Qt Programming
    Replies: 1
    Last Post: 22nd June 2010, 19:59
  3. stylesheet
    By BalaQT in forum Qt Programming
    Replies: 2
    Last Post: 19th March 2010, 07:45
  4. Qt Stylesheet
    By bunjee in forum Qt Programming
    Replies: 1
    Last Post: 22nd January 2009, 14:48
  5. Delegate but when
    By uygar in forum Qt Programming
    Replies: 1
    Last Post: 12th October 2007, 20:28

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
  •  
Qt is a trademark of The Qt Company.