Results 1 to 5 of 5

Thread: Resizing QTableView's horizontalHeader

  1. #1
    Join Date
    Jan 2006
    Location
    Edmonton, Canada
    Posts
    101
    Thanks
    13
    Thanked 6 Times in 5 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Resizing QTableView's horizontalHeader

    Hello there,

    I am using a QTableView. One of the calls I'm making to the QTableView is this:
    Qt Code:
    1. mTableView->horizontalHeader()->setFont( someFont );
    To copy to clipboard, switch view to plain text mode 
    I had noticed that if I used a large sized font, the header would be too short to display its text, so I overrode the header's setFont method in the following way:
    Qt Code:
    1. void GridHeader::setFont( const QFont & aFont )
    2. {
    3. int bufferSize = height() - fontMetrics().height();
    4. this->QHeaderView::setFont( aFont );
    5. setFixedHeight( fontMetrics().height() + bufferSize );
    6. }
    To copy to clipboard, switch view to plain text mode 
    This works like I was hoping it would - the header's height changes as the font height changes. The problem I'm encountering now is that the rest of the QTableView doesn't seem to recognize the header's height change. As a result, the first rows of the table are hidden by the header if the header's height increases.

    Is there some signal the header should be emitting when it changes height? How can I get the grid to resize properly when the header size changes?

    Jimmy

  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: Resizing QTableView's horizontalHeader

    Reimplement sizeHint() for the header.

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

    Jimmy2775 (19th December 2006)

  4. #3
    Join Date
    Jan 2006
    Location
    Edmonton, Canada
    Posts
    101
    Thanks
    13
    Thanked 6 Times in 5 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Resizing QTableView's horizontalHeader

    Yes that works. Thanks.

    Why are there functions like setFixedSize and setGeometry when the only one that seems to matter is sizeHint()?

  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: Resizing QTableView's horizontalHeader

    sizeHint is used when widget is inside a layout to indicate what size is preferred by the widget to display itself correctly. setGeometry actually resizes the widget, but when the widget is inside a layout, the layout will resize the widget back to the size calculated for it by the layout according to the sizeHint and a few other parameters. setFixedSize equals to two other calls - setMinimumSize(w,h); setMaximumSize(w,h) - it forces a constant size by fixing the range of allowed sizes. The layout should respect that setting as well as minimum and maximum sizes are taken into consideration by the layout when calculating widget's size and position.

  6. The following 4 users say thank you to wysota for this useful post:

    aya_lawliet (20th April 2011), Jimmy2775 (20th December 2006), marwyn (9th July 2011), No-Nonsense (20th December 2006)

  7. #5
    Join Date
    Jan 2006
    Location
    Edmonton, Canada
    Posts
    101
    Thanks
    13
    Thanked 6 Times in 5 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Resizing QTableView's horizontalHeader

    That is an excellent explanation - thanks.

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.