Results 1 to 4 of 4

Thread: Set height of QTableView to fit exact number of rows.

  1. #1
    Join Date
    Feb 2006
    Posts
    21
    Thanks
    4
    Thanked 1 Time in 1 Post
    Qt products
    Qt3 Qt4
    Platforms
    MacOS X Windows

    Default Set height of QTableView to fit exact number of rows.

    I have a QTableView where all rows have exactly the same height and I'd like to make the QTableView the exact height to fit a specific number of rows. Right now I'm using code like this to calculate the height needed:

    QTableView *pTableView; // The tableview whose model is filled with data.
    const int nNumRows = 10;
    int nRowHeight = pTableView->rowHeight(0);
    int nTableHeight =
    (nNumRows * nRowHeight) +
    pTableView->horizontalHeader()->height() +
    2 * pTableView->frameWidth();
    pTableView->setMinimumHeight(nTableHeight);
    pTableView->setMaximumHeight(nTableHeight);

    However, the height of the table still seems to be about 2 pixels shorter than what the rows need. Any idea what I might be missing?

    Thanks!

  2. #2
    Join Date
    Jan 2006
    Location
    Scandinavia
    Posts
    62
    Thanks
    5
    Thanked 2 Times in 1 Post
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Set height of QTableView to fit exact number of rows.

    I know what you mean. Quite irritating isn't it

    I had the same problem a while ago and debated whether or not to fix it, but it turned out that the content of my table would always be more than what the height could show - so for me the scrollbar does the trick.

    For interest's sake I would still like to see a nice solution to it.

  3. #3
    Join Date
    Jan 2014
    Posts
    1
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Windows

    Default Re: Set height of QTableView to fit exact number of rows.

    Almost 8 years later and QT 4.8.4 still has this problem. Does not happen on Windows but does happen on Mac OS. If I do not add 2 more pixels I get a scroll bar once there is 4 rows visible.

    This seems to be a difference between Windows and Mac. Adding 2 pixels to windows creates extra buffer that is not needed.
    Last edited by nteeuwenTableau; 1st February 2014 at 00:19.

  4. #4
    Join Date
    May 2014
    Posts
    1
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: Set height of QTableView to fit exact number of rows.

    I tested on Windows 10 using Qt 5.10.1. I did not have this problem.

Similar Threads

  1. QTableView has constant number of rows
    By tomeks in forum Qt Programming
    Replies: 5
    Last Post: 10th December 2008, 16:29
  2. row height in QTreeView and QTableView
    By yuriry in forum Qt Programming
    Replies: 2
    Last Post: 9th October 2008, 01:58
  3. KDE/QWT doubt on debian sarge
    By hildebrand in forum KDE Forum
    Replies: 13
    Last Post: 25th April 2007, 07:13
  4. Replies: 6
    Last Post: 5th March 2006, 22:05
  5. QTableView number of rows and scrollbar issue
    By jnk5y in forum Qt Programming
    Replies: 3
    Last Post: 1st March 2006, 07:55

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.