Trolltech Home | Qt-interest Home | Recent Threads | All Threads | Author | Date
All threads index page 5

Qt-interest Archive, July 2007
QComboBox with tree model and tree view


Message 1 in thread

Hi,

I've created a tree model and a tree view in my application that I
want to use in a QComboBox elsewhere.  I assign the model to the
combobox using QComboBox::setModel() and assign the view using
QComboBox::setView().

The ComboBox only seems to recognize root elements of the tree
(elements with no parent).  If I select the n'th child element of some
parent, the combo box instead selects the n'th child of the invisible
root node.

Is it possible to use a combo box to select children elements in a tree model?

--
 [ signature omitted ] 

Message 2 in thread

On tirsdag den 24. Juli 2007, Jim Dam wrote:
> Hi,
>
> I've created a tree model and a tree view in my application that I
> want to use in a QComboBox elsewhere.  I assign the model to the
> combobox using QComboBox::setModel() and assign the view using
> QComboBox::setView().
>
> The ComboBox only seems to recognize root elements of the tree
> (elements with no parent).  If I select the n'th child element of some
> parent, the combo box instead selects the n'th child of the invisible
> root node.
>
> Is it possible to use a combo box to select children elements in a tree
> model?

A long time ago (during the 4.0pre days, I think) I wrote a class that takes a 
tree model and flattens it to a single list for use in a combo box. I 
released it as public domain. You can try and take a look at it. Perhaps you 
can use it as is or as inspiration for doing exactly what you want.

You can find it on http://www.qt-experts.com/freebies.html. It's part of 
the "Free Qt Classes" tarball.

I hope this helps.

Sincerely,

Bo Thorsen.

-- 
 [ signature omitted ]