PDA

View Full Version : QTableView with summary footer



skuda
6th September 2011, 19:04
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.

wysota
7th September 2011, 23:54
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.

skuda
9th September 2011, 15:29
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/qt-interest/2010-February/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?

skuda
9th September 2011, 18:45
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.

skuda
9th September 2011, 20:59
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.

wysota
11th September 2011, 21:26
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.

norobro
12th September 2011, 01:31
It's amazing what you can learn from this forum. I had no idea that you could do this:

. . . 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.

skuda
12th September 2011, 10:09
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?

wysota
12th September 2011, 10:19
Use QStyle API (pixelMetric in particular) to query for sizes. QWidget::sizeHint() is also useful here.