Results 1 to 5 of 5

Thread: Question about subclassing QStyledItemDelegate

  1. #1
    Join Date
    Jul 2009
    Posts
    12
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Question about subclassing QStyledItemDelegate

    Hi guys!

    I have a subclass of QStyledItemDelegate and I want to reuse its decoration and selection painting, while painting text and other parts by myself.

    I wonder how to achieve that.
    I checked out QStyledItemDelegate's sources and found that it simply uses QStyle::drawControl() to draw CE_ItemViewItem.

    Didn't find any way to use QStyle to draw selection (ordinary + hovered) only.

    Any hints?

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Question about subclassing QStyledItemDelegate

    Make the text empty (QStyleOptionViewItemV4::text), call QStyle::drawControl() and then paint the text yourself.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  3. The following user says thank you to wysota for this useful post:

    giowck (1st August 2012)

  4. #3
    Join Date
    Jul 2009
    Posts
    12
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Question about subclassing QStyledItemDelegate

    Oh, great. But what is the proper way to convert QStyleOptionViewItem to V4 format?

    qobject_cast?

  5. #4
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Question about subclassing QStyledItemDelegate

    No, it's not a QObject. There is qstyleoption_cast or you can simply do:
    Qt Code:
    1. QStyleOptionViewItemV4 opt(option); // assuming option is QStyleOptionViewItem
    To copy to clipboard, switch view to plain text mode 
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  6. #5
    Join Date
    Jul 2009
    Posts
    12
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Question about subclassing QStyledItemDelegate

    Great. Thanks once more.

Similar Threads

  1. Replies: 2
    Last Post: 14th February 2008, 20:06

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.