Results 1 to 9 of 9

Thread: QTableView with summary footer

  1. #1
    Join Date
    Oct 2007
    Posts
    65
    Thanks
    15
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Question QTableView with summary footer

    Hi,
    i am trying to create a QTableView subclass that allows me to show a
    QHeaderView inside the viewport (above the horizontal scrollbar) with summary
    data of the columns of the model, but i am getting a difficult time getting this
    to work, anyone have created something like this and can point me in the correct
    direction please? Thanks.

    Regards,
    Miguel Angel.

  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: QTableView with summary footer

    I really wouldn't do it with QHeaderView, at least not without subclassing. Nevertheless, to do what you want, you need to reimplement resizeEvent() for the view, use setViewportMargins() to push the viewport's bottom edge upwards to make space for the additional widget and place that widget of yours into the space. You need to reposition all the components of the view manually in the resizeEvent(), that's why you need to implement it.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  3. The following 2 users say thank you to wysota for this useful post:

    norobro (12th September 2011), skuda (9th September 2011)

  4. #3
    Join Date
    Oct 2007
    Posts
    65
    Thanks
    15
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QTableView with summary footer

    I have tried this way before create the post but it seems that i don't know what i should do in resizeEvent() because i ever get a broken table.

    QTableView uses internally setViewPortMargins but it maintains the values passed in the private class and i can't find a method to get them for use in my resizeEvent so without take care of this values i end with a broken table.

    I have read too this in the documentation of QAbstractScrollArea for setViewPortMargins().

    Note that this function is frequently called by QTreeView and QTableView, so margins must be implemented by QAbstractScrollArea subclasses. Also, if the subclasses are to be used in item views, they should not call this function.
    That ended with a discussion here http://lists.qt.nokia.com/pipermail/...ry/018404.html and a bug filled later in documentation here https://bugreports.qt.nokia.com//browse/QTBUG-7941 so at this stage i am not sure if i can use it or not.

    Could you please show or point me an example on how i should do it?

  5. #4
    Join Date
    Oct 2007
    Posts
    65
    Thanks
    15
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QTableView with summary footer

    I have accepted that the headerview will be below the horizontalScrollBar so i have adjusted the tableview margin with style sheet and now i can see my headerview but i have two problems.

    1) it show empty sections (without the text) no matter what i do, i have tried create a QStandardItemModel setting horizontal labels and i have tried too to use the same model of the table but it never show any text, it seems that QHeaderView needs to be attached to a QTableView or QTreeView to work as expected.

    2) I don't know how make the headerview follow the horizontalScrollbar.

    Any ideas on how to fix that or a better idea on how to get the desired effect?

    Regards,
    Miguel Angel.

  6. #5
    Join Date
    Oct 2007
    Posts
    65
    Thanks
    15
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QTableView with summary footer

    I will compose a new widget, it seems this way QHeaderView works correctly, i was trying to get the results subclassing QTableView, but it seems that finally i will go the route of composing a new widget.

    Thanks by the help.

  7. #6
    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 with summary footer

    Quote Originally Posted by skuda View Post
    QTableView uses internally setViewPortMargins but it maintains the values passed in the private class and i can't find a method to get them for use in my resizeEvent so without take care of this values i end with a broken table.
    Calculate it yourself and store it using your own variables.

    Could you please show or point me an example on how i should do it?
    There should be such an example of mine somewhere on this forum.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  8. #7
    Join Date
    Feb 2008
    Posts
    491
    Thanks
    12
    Thanked 142 Times in 135 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11

    Default Re: QTableView with summary footer

    It's amazing what you can learn from this forum. I had no idea that you could do this:
    Quote Originally Posted by wysota View Post
    . . . you need to reimplement resizeEvent() for the view, use setViewportMargins() to push the viewport's bottom edge upwards to make space for the additional widget and place that widget of yours into the space.
    @skuda - Attached is a my first stab at the above. Hopefully it will be of some use to you.
    Attached Files Attached Files

  9. The following user says thank you to norobro for this useful post:

    skuda (12th September 2011)

  10. #8
    Join Date
    Oct 2007
    Posts
    65
    Thanks
    15
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QTableView with summary footer

    Thanks norobro, but still we have harcoded values in setViewPortMargins(), that was what i was trying to avoid and i don't know how, could we be sure that this would not break in any style or operating system?

  11. #9
    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 with summary footer

    Use QStyle API (pixelMetric in particular) to query for sizes. QWidget::sizeHint() is also useful here.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


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

    skuda (3rd February 2012)

Similar Threads

  1. TableView with header and footer for sums, avg and so on
    By extreme001 in forum Qt Programming
    Replies: 0
    Last Post: 18th April 2011, 20:56
  2. Replies: 1
    Last Post: 11th November 2009, 17:28
  3. Updating File attributes and it's summary details
    By senthilsp in forum Qt Programming
    Replies: 1
    Last Post: 11th November 2009, 13:31
  4. How to add a footer (QHeaderView) to a QTreeView?
    By DigiDrag in forum Qt Programming
    Replies: 1
    Last Post: 24th September 2008, 00:38
  5. Header and Footer
    By vermarajeev in forum Qt Programming
    Replies: 11
    Last Post: 8th December 2006, 13:10

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.