fpeelo
11th January 2008, 22:28
Hi
I want to change the way a column is displayed in a table view. Actually, I only want to display a column of booleans as checkboxes, so just selecting a different widget as the editor for all the cells in one column.
The Icons example shows a table with the editors for two columns replaced. (The Icons example also shows checkboxes in the first column. I couldn't see how to do that either, but it has to do with variants so it would be a separate topic.) This example uses QTableWidget. But I have the data in a model, as described by the "Delegate Classes" page in Qt Assistant. So the documentation for QTableWidget says I should be using QTableModel, QTableView and QItemDelegate. There is an example delegate in the documentation for using a QSpinBox as a cell control. Following this, I wrote a delegate which provides a QCheckBox editor for the cells in the table. But they don't display as checkboxes when the cell is not being edited.
In the Icons example, the cells are displayed using their custom controls by using openPersistentEditor(). I have been searching in Qt Assistant, Google and here to see how that should be used in something other than QTableWidget.
My problem is simply that, in the examples, openPersistentEditor() is used when data are added to the table. But adding data to the table is something that should be done to the table model, which does not know anything about what view is being used, whether there is a delegate or anything like that!
And the model should not know about display issues! Lots of lines are added to the table model; the view and delegate, if any, could be created much later. Then there is a setModel() so that the data can be displayed. They could be displayed in multiple views, some with persistent editors, some not.
So, only the delegate, which is the object created to make the cells display in this way, knows that the editor should be persistent. But it does not have the openPersistentEditor() method, and it does not seem to have any way to know when or how to call that method in the table view!
So, it seems to me that the view should make the editor persistent when it decides to display a cell, or maybe when it calls the delegate's createEditor() method. The delegate is the object which knows whether the editor should be persistent or not. And the actual function call to make the editor persistent is made while doing something to the data model - which should neither know nor care about the editor. Which all leaves me confused.
Are there any examples of these methods being used with the model/view architecture?
Thanks in advance
Frank
I want to change the way a column is displayed in a table view. Actually, I only want to display a column of booleans as checkboxes, so just selecting a different widget as the editor for all the cells in one column.
The Icons example shows a table with the editors for two columns replaced. (The Icons example also shows checkboxes in the first column. I couldn't see how to do that either, but it has to do with variants so it would be a separate topic.) This example uses QTableWidget. But I have the data in a model, as described by the "Delegate Classes" page in Qt Assistant. So the documentation for QTableWidget says I should be using QTableModel, QTableView and QItemDelegate. There is an example delegate in the documentation for using a QSpinBox as a cell control. Following this, I wrote a delegate which provides a QCheckBox editor for the cells in the table. But they don't display as checkboxes when the cell is not being edited.
In the Icons example, the cells are displayed using their custom controls by using openPersistentEditor(). I have been searching in Qt Assistant, Google and here to see how that should be used in something other than QTableWidget.
My problem is simply that, in the examples, openPersistentEditor() is used when data are added to the table. But adding data to the table is something that should be done to the table model, which does not know anything about what view is being used, whether there is a delegate or anything like that!
And the model should not know about display issues! Lots of lines are added to the table model; the view and delegate, if any, could be created much later. Then there is a setModel() so that the data can be displayed. They could be displayed in multiple views, some with persistent editors, some not.
So, only the delegate, which is the object created to make the cells display in this way, knows that the editor should be persistent. But it does not have the openPersistentEditor() method, and it does not seem to have any way to know when or how to call that method in the table view!
So, it seems to me that the view should make the editor persistent when it decides to display a cell, or maybe when it calls the delegate's createEditor() method. The delegate is the object which knows whether the editor should be persistent or not. And the actual function call to make the editor persistent is made while doing something to the data model - which should neither know nor care about the editor. Which all leaves me confused.
Are there any examples of these methods being used with the model/view architecture?
Thanks in advance
Frank