PDA

View Full Version : Different number of columns in each row



1111
3rd March 2009, 15:08
Hello all,

Is it possible to create QTreeWidget or QTreeView element with different number of columns in each row? I need to create widget that behaves as a tree (can collapse and expand) but have different widget in each row. I believe that row widgets can be represented as a cells, but number of columns in each row may be vary.

Is there any model to represent create such tree?

caduel
3rd March 2009, 15:59
no.
with the signature

int columnCount(const QModelIndex& parent)
you are forced to have the same number of colums for all rows of a parent index.
(Moreover, the views don't support something like that.)

You can create a view that 'stops' at the first column to return an empty QVariant() for the Qt::DisplayRole. That is *your* convention then...

1111
5th March 2009, 16:27
But is it possible to put QWidget instead of item data in the tree?

I mean QTreeView has same structure and only one column, but each line in the QTreeView is a custom widget.

aamer4yu
5th March 2009, 17:07
Just wondering... is it a good idea to have all your cells as widgets ?
I dont think so... there must be some other way to achieve your goal...:rolleyes:

1111
5th March 2009, 17:25
Just wondering... is it a good idea to have all your cells as widgets ?
I dont think so... there must be some other way to achieve your goal...:rolleyes:

But are common widgets do the same? I thought QTreeView and QTableView use QLabel and QLineEdit to show information on the screen.

caduel
5th March 2009, 17:37
no, they do not.
they use "delegates" to render the data. they only create widgets for editing data.

see QItemDelegate, model-view-delegate

1111
9th March 2009, 09:44
Thanks for tips.

It looks like, this is the way how I should implement my widgets.

There is paint() function that must be implemented if you subclass delegate class. This function must manually draw a widget, but my widget is a splitter that contains several QLabels inside. Is there any function or class that helps me to draw it fast? :rolleyes:

I know there are drawControl(), drawPrimitive() and drawComplex() functions that can draw some widgets automatically. But non of them can draw splitter for instance or calculate layout sizes. However, if you create a widget and insert it into window, application automatically draw it, so application use some functions for calculating components size and location.

To sum it up :) my question is, are there any functions that I can use inside paint() function in my delegate class, that can automatically draw composite widgets?
:confused:

Any tips are appreciated.