PDA

View Full Version : QTableView Custom Item Approach



ForestDweller2
3rd July 2018, 21:40
Not sure what "Beginner" means, I have been using Qt for many years

I have a working QTableView with QSqlRelationalTableModel and custom QHeaderView that functions well but without the two features shown in the attached image.
Namely:

the "expanded view" between rows 3 and 4 (row 3 selected)
the "Session" grouping shown at line 9 (that requires drag-n-drop functionality to "ungroup" items)


I am aware of classes such as QAbstractTableModel, but have extremely limited experience with them.
I am thinking that what is required is a custom QSqlRelationalDelegate but the documentation for it would suggest that it is intended for items (column data) rather than rows.

I was considering a QTableWidget with custom QTableWidgetItems, (which I have experience with), but I currently enjoy the benefits of the great integration of the QTableView, QSqlRelationalTableModel and custom QHeaderView that works so well...

I would like some suggested approaches to providing the missing functionality.

d_stranz
4th July 2018, 01:04
Not sure what "Beginner" means, I have been using Qt for many years

How is the forum software to know that? It only knows how long and how often you've posted or replied to posts. With one post, you're a Beginner.

As for your requirement, it is difficult to see from your screenshot whether what you are showing is an expanded detail view of the selected row or whether it is a widget that overlays the table. There is a commercial product, QTitanDataGrid, that supports the first concept, of an expanded detail view. I've never used it but it seems to have some interesting features. If what you want is simply an overlay, then you could pop up a QWidget-based modal widget containing the details, positioned such that it sits under the selected row. There isn't anything in the off-the-shelf QTableView to support either of these, so you'd have to write (or buy) it.

ForestDweller2
4th July 2018, 03:44
How is the forum software to know that?
Well thanks, now I know that "beginner" refers to my (lack of) time spent on forum and not Qt experience.

Perhaps my lack of forum etiquette also prevents me from understanding why you cannot see the "screenshot" clearly.
When I click on my posts' attached thumbnail I can see it clearly.


There isn't anything in the off-the-shelf QTableView to support either of these, so you'd have to write (or buy) it.
Well yes, that is why I was asking for suggested approaches to writing it myself. Or maybe my post was not clear about that.

When using a QTableWidget, you can create custom table items by sub-classing QTableWidgetItems.
I have implemented many such solutions.
I am merely trying to find a similar solution for QTableView.

I am inclined to think the solution involves a custom delegate.

NOTE:
The data displayed is not editable (with one exception). It is just a consolidated view of a combination of data tables.
And the view is row oriented rather than spreadsheet oriented
The exception is that (in the second case) items may be dragged out of the parent item (labeled "Session") to become normal items.

d_stranz
4th July 2018, 05:48
The image was smallish and not very legible on my 4K monitor, so it is not easy to tell what it is you are trying to display. It's a problem I have with many of the images posted here.

My understanding of item delegates is that they are displayed within the rectangle bounds of the table cell. What you are showing in the center of your screenshot seems to be sized and positioned independently of any particular cell. If you do use a delegate, maybe you can play with paint(), sizeHint(), and clipping to achieve what you want.