Results 1 to 3 of 3

Thread: Different size hint for selected cells in QListItemView

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Oct 2009
    Posts
    2
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Different size hint for selected cells in QListItemView

    Hello, I am trying to implement an item delegate for a list view which should display additional information for any selected item. In order to display this additional information, I would need to allocate more space on screen to the selected item. For this, I tried to implement sizeHint() of the item delegate in the following way:

    Qt Code:
    1. QSize MyDelegate::sizeHint(const QStyleOptionViewItem& option, const QModelIndex& index) const
    2. {
    3. const bool sel(option.state.testFlag(QStyle::State_Selected));
    4.  
    5. QSize size1;
    6. QSize size2;
    7.  
    8. /* compute size1 and size2... */
    9.  
    10. if (sel)
    11. {
    12. return size1;
    13. }
    14. else
    15. {
    16. return size2;
    17. }
    18. }
    To copy to clipboard, switch view to plain text mode 

    However, flag State_Selected does not seem to be set when the size hint is requested from the delegate. Is it a known fact that this flag is set only after the sizeHint method has been called, or am I doing something wrong?

    Thanks,

    Andras

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

    Default Re: Different size hint for selected cells in QListItemView

    It's a known fact it is not called for sizeHint(). The thing you want to do can't be easily implemented currently. All you can do is to tell your item it is selected and then signal size hint changed from the delegate so that sizeHint is queried again and returns modified data.
    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. #3
    Join Date
    Oct 2009
    Posts
    2
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: Different size hint for selected cells in QListItemView

    Hi, wysota, thanks for making that clear. For now, I think I'll stick with uniform size -- the other solution seems a little complicated...

Similar Threads

  1. QDockArea size hint
    By ksierens in forum Qt Programming
    Replies: 2
    Last Post: 5th April 2006, 15:37

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