Results 1 to 9 of 9

Thread: QTableView row heights

  1. #1
    Join Date
    Mar 2006
    Location
    Mountain View, California
    Posts
    489
    Thanks
    3
    Thanked 74 Times in 54 Posts
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows

    Question QTableView row heights

    QTableViews have much thicker rows/cells than Qt3 QTables did. They appear to have about a 6 pixel padding. This is wasting too much screen real estate, and in my opinion looks unprofessional.

    What is the best way to resize the rows? I was using resizeRowsToContents(), but it's not quite right. What I want is something on the order of the row heights in Designer's property editor. I'm not understanding the Designer code and so I can't find how they do it. The default height (with my font) is 30 pixels. Using resizeRowsToContents I get 27 pixels. Designer has 21 pixels. See the difference?

    Any hints?

  2. #2
    Join Date
    Jan 2006
    Posts
    667
    Thanks
    10
    Thanked 80 Times in 74 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QTableView row heights

    void QTableView::setRowHeight ( int row, int height )
    Sets the height of the given row to be height.
    This function was introduced in Qt 4.1.

  3. #3
    Join Date
    Mar 2006
    Location
    Mountain View, California
    Posts
    489
    Thanks
    3
    Thanked 74 Times in 54 Posts
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: QTableView row heights

    There's no way to adjust the height automatically based on the current font? Otherwise I have to calculate the font sizes myself. I can certainly do this, but it seems to me that Qt should be doing this kind of low level stuff for me. After all, I don't have to do it for any other widget.

    Is this really how Designer does it?

  4. #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: QTableView row heights

    You may use a custom delegate with different padding values.

  5. #5
    Join Date
    Mar 2006
    Location
    Mountain View, California
    Posts
    489
    Thanks
    3
    Thanked 74 Times in 54 Posts
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: QTableView row heights

    I'm not sure exactly what you mean. I looked in QItemDelegate source, and I see that there is a hardcoded text margin of 3. Is this what you mean? It is the only thing I can find that could be considered "padding". Will I have to rewrite all of QItemDelegate's display code in order to resize some rows? In such a case I might as well inherit from QAbstractItemDelegate instead!

    I am aghast that something that should be simple is so difficult. Am I just being stupid?

  6. #6
    Join Date
    Mar 2006
    Location
    Mountain View, California
    Posts
    489
    Thanks
    3
    Thanked 74 Times in 54 Posts
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: QTableView row heights

    Solved! It turns out that even though the vertical header is hidden, it is still being used to calculate the minimum row height. The only way I can figure to change this is by tweaking the font size for the header. Since it's hidden the smaller font won't be seen. That's probably not the best solution, but it works.
    Last edited by Brandybuck; 7th April 2006 at 08:10. Reason: solution found

  7. #7
    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: QTableView row heights

    Quote Originally Posted by Brandybuck
    I'm not sure exactly what you mean. I looked in QItemDelegate source, and I see that there is a hardcoded text margin of 3. Is this what you mean? It is the only thing I can find that could be considered "padding". Will I have to rewrite all of QItemDelegate's display code in order to resize some rows? In such a case I might as well inherit from QAbstractItemDelegate instead!

    I am aghast that something that should be simple is so difficult. Am I just being stupid?
    Item size is determined by the size returned by delegate's sizeHint method, which is in turn based on getting data from SizeHintRole of the item, so you can either reimplement sizeHint(), set data for SizeHintRole of the items (or the whole model) or reimplement the delegate's painting routine (note that this will not alter the cell size, only its content).

  8. #8
    Join Date
    Mar 2006
    Location
    Mountain View, California
    Posts
    489
    Thanks
    3
    Thanked 74 Times in 54 Posts
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: QTableView row heights

    Quote Originally Posted by wysota
    Item size is determined by the size returned by delegate's sizeHint method.
    I eventually discovered that, but it wasn't working for me. My problem was that the QHeaderView was placing a minimum size on the row heights, so that while I could make the rows bigger, I could not make them smaller. See my solution above.

  9. #9
    Join Date
    Nov 2006
    Location
    Dresden, Germany
    Posts
    108
    Thanks
    9
    Thanked 12 Times in 10 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: QTableView row heights

    I still have a problem with my row heights. I cannot make the font of my headers smaller, because I use them. And the size hint I set in my costum item delegate only works for the actual table cells, but not for the headers.

    Does anyone know how I can set the row heights for the headers?

    Bye,
    Andreas

Similar Threads

  1. Replies: 3
    Last Post: 29th January 2009, 08:38
  2. QTableView in ui with model/delegate
    By tpf80 in forum Qt Programming
    Replies: 7
    Last Post: 6th November 2008, 23:00
  3. row height in QTreeView and QTableView
    By yuriry in forum Qt Programming
    Replies: 2
    Last Post: 9th October 2008, 00:58
  4. make QTableView work as a multi-column list view
    By wesley in forum Qt Programming
    Replies: 1
    Last Post: 11th March 2008, 14:43
  5. Multi-line messages in QTableView
    By Conel in forum Qt Programming
    Replies: 6
    Last Post: 13th April 2006, 13:49

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.