PDA

View Full Version : setCellWidget for every row



gemidjy
24th March 2008, 18:37
I have a table with 5 columns and many rows. Now, is there a way to set a Widget for the first column in the table, but for all of its rows, without iterating through all of the rows and setting the widget with setCellWidget(..)?

And one more, I couldn't figure a way to findout when an editing is started in certain cell? Thanks

jpn
24th March 2008, 22:11
I have a table with 5 columns and many rows. Now, is there a way to set a Widget for the first column in the table, but for all of its rows, without iterating through all of the rows and setting the widget with setCellWidget(..)?
No, you will have to instantiate as many widgets as there are rows anyway. You can't set the same widget in multiple cells. Anyway, what does this cell widget do? Keep in mind that they are expensive to maintain and that flooding your view full of them makes the model-view framework useless.


And one more, I couldn't figure a way to findout when an editing is started in certain cell?
Just curious, what do you need that information for? It's the delegate who creates the editor.

gemidjy
24th March 2008, 22:17
No, you will have to instantiate as many widgets as there are rows anyway. You can't set the same widget in multiple cells. Anyway, what does this cell widget do? Keep in mind that they are expensive to maintain and that flooding your view full of them makes the model-view framework useless.


Just curious, what do you need that information for? It's the delegate who creates the editor.

As a matter of fact, I am in a delicate situation now. I need to use QTableWIdget to insert new data in a database. I think that it is better to use widget instead of QTableView on which a model is installed since everytime the dialog is created, an empty set in the table should appear (and if I use view/model the existent data would be shown except If I don't use filters and proxies...So, every time new data would go in the tablewidget and then commit to the database...thus, I need completion of data from within the cells, so that it reads existent records from the database and offer auto-completion (via QCompleter)

If you have any better idea than this, I think that I would gladly use it since this is, as you said, very expensive idea.

jpn
24th March 2008, 22:19
So, what do cell widgets have to do with this scenario? :)

gemidjy
24th March 2008, 22:23
So, what do cell widgets have to do with this scenario? :)

To set a completer I have to set it in a cell, but I can't get the cell as *widget on which I can install the Completer, right? :eek:

gemidjy
24th March 2008, 22:25
Maybe the best solution is if I could make the view not show any data until new is inserted, and then after I press a key to get it "unvisible" too....

jpn
24th March 2008, 22:27
To set a completer I have to set it in a cell, but I can't get the cell as *widget on which I can install the Completer, right? :eek:
The item delegate is responsible for creating an editor widget every time editing begins. There are no widgets when the view is in non-editing state. This is what makes the view so light-weight. What you should do is to subclass QItemDelegate, reimplement createEditor(), call base class implementation to create the editor, try casting it as QLineEdit and install a completer if appropriate.

gemidjy
24th March 2008, 23:03
ahm...will take your advice..thanks!