PDA

View Full Version : List or Table or Grid or Tree or ... ?? What to pick?



Martin
8th September 2006, 17:00
I'm looking for a Qt equivalent of Mac OS X's Data Browser API.

There seem to be a few different options (List, Grid, Tree, Table) but none of them seem to offer everything that I need in one place.

Here are my list of requirements:

1. Resizable, rearrangeable and sortable columns
2. Ability to display and edit checkbox, combobox (menu in Mac-land), text, icon, per column (no edit required for icons)
3. Ability to disable a single row, preventing selection & editing

If anyone here knows the Data Browser API from Mac OS X then you'll know what I'm after :D

Is this available? If so, where do I start? I've already had a number of false starts...

Thanks!

wysota
8th September 2006, 17:36
You can use QTableView or QTreeView to achieve all that.

Martin
11th September 2006, 11:54
Thanks for your reply, but unfortunately this didn't help me.

To give you an example of the problem I face, let me explain what I have found so far:

In comparing the QTreeView to QTableView, it appears that Tree provides resizable, reorderable and sortable columns with the correct platform appearance. Table, on the other hand, only offers resizable columns. However, Table seems to provide built-in checkbox, combobox and text in-place editing and display, whereas Tree view does not.

I did try working with a Tree view but found that although I can specify delegate checkbox and combobox editors, it's not so easy to use the same widgets to just display the data. I did manage to get a checkbox to display via a custom 'paint' but there were problems such as the background not being correct when the row was selected. Worse still, I couldn't find a way of just drawing a combobox.

Am I missing something or does everyone override the base views heavily to get this kind of functionality?

Thanks again.

jpn
11th September 2006, 12:48
Table seems to provide built-in checkbox, combobox and text in-place editing and display, whereas Tree view does not.
Not correct. Both can have exactly the same editors. QTableView and QTreeView use the same delegate, QStandardItemDelegate that is, by default. QStandardItemDelegate offers different kind of editors depending on the type of the variant data:
- QComboBox for booleans
- QSpinBox for integers (both signed and unsigned)
- QDoubleSpinBox for doubles
- QDateTimeEdit for datetimes
- QDateEdit for dates
- QTimeEdit for times
(- QLabel for pixmaps)
- QLineEdit otherwise

The corresponding editor appears when your model returns the data in appropriate format. A common mistake is to insert all data as text. By this way you'll end up always having a QLineEdit as the editor.

For checkable items, the model needs to return appropriate flag for indexes you want to be checkable. Items are not checkable by default, you can override QAbstractItemModel::flags() and return Qt::ItemIsUserCheckable among the other needed flags to make items checkable. The same model can be used in any view (QTableView, QTreeView..) and they appear as checkable.


Am I missing something or does everyone override the base views heavily to get this kind of functionality?
Hardly. All you have described IS supported kind of "out of the box".

wysota
11th September 2006, 14:13
Am I missing something or does everyone override the base views heavily to get this kind of functionality?

I suggest you familiarise yourself with model-view programming (http://doc.trolltech.com/4.1/model-view-programming.html) with Qt4, especially with the concept of roles and delegates.