Results 1 to 16 of 16

Thread: QTableView: sizeHint() not getting invoked for custom delegate

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,373
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Thanks
    3
    Thanked 5,019 Times in 4,795 Posts
    Wiki edits
    10

    Default Re: QTableView: sizeHint() not getting invoked for custom delegate


  2. #2
    Join Date
    Oct 2007
    Location
    India
    Posts
    162
    Qt products
    Qt4
    Platforms
    Unix/X11
    Thanks
    20
    Thanked 6 Times in 5 Posts

    Default Re: QTableView: sizeHint() not getting invoked for custom delegate

    i can try using QTableView::resizeRowsToContents() but i am not sure it will work for me properly. I am drawing the text being displayed in the table rows myself in the paint() function. So, to display only 8 rows in the table at a time, i increase the font size but from where will QTableView::resizeRowsToContents() get the sizeHint? I guess it will use the default size hint. But i want to specify the size hint myself so that i can control the row height myself.
    I'll try using QTableView::resizeRowsToContents() tomorrow when i work on the code.

    And the most important question is that why isn't sizeHint() getting called for QTableView? Is it a known issue? I don't think it is mentioned anywhere in the Qt Documentation that sizeHint() doesn't work for QTableView, so i guess it's a bug. Even if it doesn't work, there should be atleast some way to specify the row height in QTableView.

    Can you try to run the sample application code i posted and observe the difference in behavior of sizeHint() for QTableView and QListView?

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

    Default Re: QTableView: sizeHint() not getting invoked for custom delegate

    Quote Originally Posted by montylee View Post
    I guess it will use the default size hint.
    It will ask the delegate for the size hint.

    And the most important question is that why isn't sizeHint() getting called for QTableView?
    Because in the default mode the headers control cell sizes, not the other way round. If you change the resize mode of the headers to ResizeToContents it will ask the contents for the size.

    Is it a known issue?
    Yes, it's called a feature

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

    montylee (19th February 2009)

  5. #4
    Join Date
    Oct 2007
    Location
    India
    Posts
    162
    Qt products
    Qt4
    Platforms
    Unix/X11
    Thanks
    20
    Thanked 6 Times in 5 Posts

    Default Re: QTableView: sizeHint() not getting invoked for custom delegate

    aah, you are right! After calling QTableView::resizeRowsToContents() sizeHint() is being called and looks like my problem is resolved

    I'll test this code in my main application tomorrow.

    Thanks!!! looks like once again you rescued me

  6. #5
    Join Date
    Oct 2007
    Location
    India
    Posts
    162
    Qt products
    Qt4
    Platforms
    Unix/X11
    Thanks
    20
    Thanked 6 Times in 5 Posts

    Default Re: QTableView: sizeHint() not getting invoked for custom delegate

    ok, i am able to set the row height properly now in my main application.
    So, this was not a bug i guess. But it should be mentioned in the documentation of sizeHint() that one needs to use set QTableView::resizeRowsToContents() and QTableView::resizeColumnsToContents() to use sizeHint.

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

    Default Re: QTableView: sizeHint() not getting invoked for custom delegate

    Why should the docs of the delegate contain information about a special behaviour of some other widget? The information you are looking for is there, just not in the place you were looking for it.

    See QHeaderView::ResizeMode, especially the last (not counting the one in brackets) sentence from the Interactive value description and first sentence of ResizeToContents value description.

  8. #7
    Join Date
    Jan 2008
    Location
    Germany
    Posts
    80
    Qt products
    Qt4
    Platforms
    MacOS X Windows
    Thanks
    6
    Thanked 1 Time in 1 Post

    Default Re: QTableView: sizeHint() not getting invoked for custom delegate

    Where is resizeRowsToContents() supposed to be called when the model gets updated?

  9. #8
    Join Date
    Dec 2012
    Posts
    1
    Platforms
    Windows

    Default Re: QTableView: sizeHint() not getting invoked for custom delegate

    I know this is resurrecting an old thread, but I wound-up here when trying to figure out why sizeHint wasn't being called when overridden in a custom QGraphicsWidget.
    Someone might wind-up here, so I'll add my discovery that having called setContentsMargins at any time before layout will solve this problem.

Similar Threads

  1. QTableView sizeHint() issues
    By akos.maroy in forum Qt Programming
    Replies: 3
    Last Post: 20th September 2008, 22:42

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.