Results 1 to 2 of 2

Thread: Separating QHeaderView from QTableView

  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 Separating QHeaderView from QTableView

    I am using a QTableView to display data. The problem I've encountered is that the table has so many rows, it is possible for users to scroll down the table so that the column headers go out of view, which is not good.

    My solution for this is to move the table's QHeaderView outside the QTableView. The table sits inside a QScrollArea, so I want to move the header above the QScrollArea. I've done it this way:
    Qt Code:
    1. QHeaderView* iHeaderView = mTableView->horizontalHeader();
    2. iHeaderView->setParent( headerPlaceHolder );
    To copy to clipboard, switch view to plain text mode 
    In the above code, headerPlaceHolder is a QFrame that is positioned where I want the header to be. If I run the code, the grid is drawn without the header, but the header does not appear in the placeholder frame. I've tried to resolve this in two ways:
    1. I call show() on the QHeaderView.
    2. I add a layout to the placeholder frame and call addWidget(), passing in the QHeaderView.
    Either way has the same result - the header appears where I want it to, but the grid is drawn with space allotted for the header. Does anyone know how I could eliminate this space? I've looked through the QTableView and QAbstractItemView code but I can't seem to find the problem - I'm not even sure what to look for.

    Also, has anyone tried anything similar to what I'm trying to do here? I'm not sure if I'm taking the right approach to this.

    Jimmy

  2. #2
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: Separating QHeaderView from QTableView

    You will have to look into QTableView::paintEvent() sources, I'm afraid. QTableView paints itself according to the offsets and coords retrieved from the header views.
    J-P Nurmi

Similar Threads

  1. Set height of QTableView to fit exact number of rows.
    By Ben.Hines in forum Qt Programming
    Replies: 3
    Last Post: 17th January 2019, 01:49
  2. QTableView sorting
    By gabriels in forum Qt Programming
    Replies: 11
    Last Post: 6th October 2010, 17:13
  3. QTableView currentChanged <> selecting header
    By Everall in forum Qt Programming
    Replies: 4
    Last Post: 1st April 2009, 08:24
  4. QTableView paints too much
    By Jimmy2775 in forum Qt Programming
    Replies: 2
    Last Post: 26th July 2006, 18:42
  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.