Results 1 to 5 of 5

Thread: Subclassed QItemDelegate::sizeHint and is the item selected?

  1. #1
    Join Date
    Jan 2006
    Location
    Germany
    Posts
    4,380
    Thanks
    19
    Thanked 1,005 Times in 913 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60
    Wiki edits
    5

    Default Subclassed QItemDelegate::sizeHint and is the item selected?

    Hi,

    I have an subclassed QItemDelegate to draw my own content to a QListView. In the sizeHint function I need to know if the item is selected. Unfortunately the given QStyleOptionViewItem doesn't hold this information. The only way I see is the selection model of the parent QListView. But how I get a pointer the the QListView out of the "QItemDelegate::sizeHint()" with the given QModelIndex or QStyleOptionViewItem?


    Thanks,

    Lykurg

  2. #2
    Join Date
    Dec 2006
    Posts
    849
    Thanks
    6
    Thanked 163 Times in 151 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: Subclassed QItemDelegate::sizeHint and is the item selected?

    isn't QStyleOptionViewItem::state & QStyle::State_Selected set?

  3. #3
    Join Date
    Jan 2006
    Location
    Germany
    Posts
    4,380
    Thanks
    19
    Thanked 1,005 Times in 913 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60
    Wiki edits
    5

    Default Re: Subclassed QItemDelegate::sizeHint and is the item selected?

    Quote Originally Posted by caduel View Post
    isn't QStyleOptionViewItem::state & QStyle::State_Selected set?
    No, that's the point. In my paint function it is set:
    QStyleOption( SO_ViewItem , LeftToRight , QStyle::State( "Active | Enabled | HasFocus | Selected" ) , QRect(0,0 778x100) )
    but in the sizeHint function it is only
    QStyleOption( SO_ViewItem , LeftToRight , QStyle::State( "Active | Enabled" ) , QRect(0,0 100x300) )

  4. #4
    Join Date
    Dec 2006
    Posts
    849
    Thanks
    6
    Thanked 163 Times in 151 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: Subclassed QItemDelegate::sizeHint and is the item selected?

    the idea is probably that the size should not change when an item is selected.
    (which is reasonable: otherwise you get a kind of "wobbling" effect as things have to be relayouted all the time just because you selected a different item...)

  5. #5
    Join Date
    Jan 2006
    Location
    Germany
    Posts
    4,380
    Thanks
    19
    Thanked 1,005 Times in 913 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60
    Wiki edits
    5

    Default Re: Subclassed QItemDelegate::sizeHint and is the item selected?

    But this is exactly what I want. A bigger size for selected items. And I think sizeHint is requested when the item gets selected. For example I have three items and when I hide the window, sizeHint debug says:

    sizeHint QStyleOption( SO_ViewItem , LeftToRight , QStyle::State( "Enabled" ) , QRect(0,0 100x300) ) 0
    sizeHint QStyleOption( SO_ViewItem , LeftToRight , QStyle::State( "Enabled" ) , QRect(0,0 100x300) ) 1
    sizeHint QStyleOption( SO_ViewItem , LeftToRight , QStyle::State( "Enabled" ) , QRect(0,0 100x300) ) 2

    The last number is item index. So for all items sizeHint is requested, but item 0, which is selected, doesn't show the selection state in QStyle::State :-(

    Lykurg

Similar Threads

  1. Item Delegate Painting
    By stevey in forum Qt Programming
    Replies: 3
    Last Post: 9th May 2008, 07:37
  2. Changing selected item color in non-current window.
    By Doug Broadwell in forum Qt Programming
    Replies: 1
    Last Post: 26th August 2007, 07:09
  3. QTreeView: selection behavior upon selected item removal
    By Pieter from Belgium in forum Qt Programming
    Replies: 6
    Last Post: 11th July 2007, 16:00
  4. QListWidget/QTreeWidget, etc selected item color
    By Arthur in forum Qt Programming
    Replies: 4
    Last Post: 15th May 2006, 16:50
  5. Replies: 1
    Last Post: 23rd March 2006, 06: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.