PDA

View Full Version : Modified tableview



dkite
11th March 2006, 22:22
I would like to have a tableview, getting data from a relational sql model. The tableview would display a few of the fields of the table, but when a row is selected, allow editing of all the fields in some kind of dialog type widget contained within an enlarged row of the table view.

The delegate classes draw and edit cells, ie a certain row/column. You can paint or customize the cell, but not the whole row at a time. Or so I can determine.

Obviously I'm going to have to subclass a bunch of things, but where would a person start? Which class initiates the drawing sequences, initiates the what eventually calls the delegate to generate an editor?

I thought of modifying the model class to output a 1 column tableview, then painting the wide cell with the fields in the unselected rows. The selected row would be made larger, and a widget with editing widget children used. Does that make sense?

Thanks
Derek

wysota
12th March 2006, 16:34
You don't have to subclass anything. You just need to connect some signals of your choice to a custom slot which will create a QDialog based dialog and fill it with widgets to edit the fields. All field data can be taken from the model itself using the record() method.

dkite
14th March 2006, 01:58
Reading the qtableview code, I think I can see a way forward.

On a call for the table to paint, the method figures out columns and rows from the qheaderviews. It then iterates through the rows, and calls the delegate to draw each cell, passing info such as selected and other so the delegate can draw properly. It then draws the grid if required. The delegate gets the record and field data from the model.

If I subclass the tableview paint method, if not selected proceed as normal, if selected, (or even better, if current) flag it as such, get the size hint from the delegate, and give it the row height and full width of the table. The delegate could then draw the widgets as required.

I don't want to pop up another dialog. The table contains data that needs to be handled and passed onto somewhere else. The tableview would show only 3 columns, but to edit requires another 4 widgets plus some buttons to take some action. The selected row would show all the widgets, the non selected would look like normal tableview rows and columns.

Derek