Results 1 to 9 of 9

Thread: Freeze any row within a QTableWidget/View

  1. #1
    Join Date
    Jan 2015
    Posts
    22
    Thanks
    3
    Qt products
    Qt5
    Platforms
    Windows

    Default Freeze any row within a QTableWidget/View

    Sorry if this question has been asked a few times (with different variations), but I got this specific problem. I'm trying to create a custom table widget which can freeze a single row within the table. The frozen row then will act like a footer, but its position will change according to the scrollbar. If the scrollbar scroll beneath the row, the frozen row will stick to the top of the table. If the scrollbar scroll above the row, it will be at the bottom of the table.
    The frozen column example makes do by overlaying a static model on top of the actual data model, but the overlay will be apparent for rows in the middle of the table. Is it possible to do this with a QTableWidget/QTableView (with a custom item model)?

  2. #2
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: Freeze any row within a QTableWidget/View

    What you are asking for is entirely in the view and nothing to do with the model.

    Why do you think the overlay will be apparent for rows in the middle of the table? It certainly is a more tricky exercise to keep the overlay in the correct place, but I do not see an obvious difference in approach.

  3. #3
    Join Date
    Jan 2015
    Posts
    22
    Thanks
    3
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: Freeze any row within a QTableWidget/View

    Sorry for replying too long.. I was looking for a method to customize the viewport within the QTableWidget itself. Now I use the same principle (QTableView within QTableWidget). By the example, the position of the overlay is connected to the resizeEvent and updateFrozenTableGeometry functions right? So all I need is to modify those functions?

  4. #4
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: Freeze any row within a QTableWidget/View

    You will have to capture scrolling events or check every time the base widget is painted to allow the overlay to track the vertical position of the row it is sitting above (or only show the overlay at top or bottom when the row of interest is not totally visible).
    QTableView::rowViewportPosition()QTableView::rowHeight()

  5. The following user says thank you to ChrisW67 for this useful post:

    Baltharos (4th March 2015)

  6. #5
    Join Date
    Jan 2015
    Posts
    22
    Thanks
    3
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: Freeze any row within a QTableWidget/View

    So I need to connect the scrollbar to the geometry function?

  7. #6
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: Freeze any row within a QTableWidget/View

    Maybe by overriding scrollContentsBy(), calling the parent class function and then looking at where the overlaid table should be positioned. The effective row position might change if you resize the widget also. Perhaps just reevaluating the overlay positioning inside a the parent widget's painteEvent() is possible. There are quite a few variables and it will take a bit of experimenting to find them all.

  8. The following user says thank you to ChrisW67 for this useful post:

    Baltharos (4th March 2015)

  9. #7
    Join Date
    Jan 2015
    Posts
    22
    Thanks
    3
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: Freeze any row within a QTableWidget/View

    The scrolling now works! But how if I want to freeze a row that isn't in the viewport right now? Using rowViewportPosition, the function failed when I try a big row number.

  10. #8
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: Freeze any row within a QTableWidget/View

    What do you mean "failed"?
    Has the row in question been fetched from the model by the view? The view uses lazy fetching with canFetchMore() and fetchMore().

  11. #9
    Join Date
    Jan 2015
    Posts
    22
    Thanks
    3
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: Freeze any row within a QTableWidget/View

    Found the problem (for now). The code can't take the tablewidget's verticalHeaderItem->text(). The horizontalHeaderItem works fine though. Why is it?

Similar Threads

  1. Replies: 1
    Last Post: 20th April 2013, 19:53
  2. Fixed (Freeze) column in QTableWidget
    By chatarpal in forum Qt Programming
    Replies: 4
    Last Post: 21st January 2012, 07:03
  3. CSV file content to QTablewidget view
    By vishnu in forum Newbie
    Replies: 5
    Last Post: 22nd October 2010, 11:04
  4. Resizing headers view in the QTableWidget
    By jano_alex_es in forum Qt Programming
    Replies: 1
    Last Post: 27th January 2010, 11:55
  5. QTableWidget view problem
    By zgulser in forum Qt Tools
    Replies: 6
    Last Post: 5th March 2009, 07:50

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
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.