PDA

View Full Version : Multible QCombobox tree with model view



mrandreas
6th September 2010, 17:07
Hi

I have a simple tree that i want to present in QCombobox:

A
-a
-b
-c
B
-e
-f
C

5150

When selecting A in the first combobox, I want to populate the children A (a, b, c) in the second combox. I have used the qt example simpletreemodel. I tryed to fidle with the QDataWidgetMapper without anny success. What is the right way too go here (qt way)?

Anny good ideas?

tbscope
7th September 2010, 05:48
QComboBox::setModel(your model)
QComboBox::setRootModelIndex(index of the first combobox)

mrandreas
22nd September 2010, 14:00
thanks...


void ComboBoxTreeView::updateRootModelIndex()
{
if(m_model == 0)
return;
int size = m_group->count();
for(int i = 0; i < size;i++)
{
QComboBox* box = m_group->getComboBox(i);
if(i > 0)
{
QComboBox *parent = m_group->getComboBox(i-1);
if(parent->isWidgetType())
{
QModelIndex pindex = parent->rootModelIndex();
box->setRootModelIndex(pindex.child(parent->currentIndex(),0));
}
}
else if(i == 0)
{
box->setRootModelIndex(m_model->index(0,0));
}
}
}