I'm trying to use a QTreeView as a view for a QComboBox.
I've done something like this:
TreeView m_view = new TreeView(this);
m_combo->setModel(m_view->getModel());
m_combo->setView(m_view);
QStandardItem* item4 = new QStandardItem("Four");
m_view->getModel()->appendRow(item1);
item1->appendRow(item2);
m_view->getModel()->appendRow(item3);
m_view->getModel()->appendRow(item4);
TreeView m_view = new TreeView(this);
QComboBox* m_combo = new QComboBox(this);
m_combo->setModel(m_view->getModel());
m_combo->setView(m_view);
QStandardItem* item1 = new QStandardItem("One");
QStandardItem* item2 = new QStandardItem("Two");
QStandardItem* item3 = new QStandardItem("Three);
QStandardItem* item4 = new QStandardItem("Four");
m_view->getModel()->appendRow(item1);
item1->appendRow(item2);
m_view->getModel()->appendRow(item3);
m_view->getModel()->appendRow(item4);
To copy to clipboard, switch view to plain text mode
My questions are:
1) Am I doing the right thing there?
2) How can I select an item from the list?
3) How can I know when an item has been selected?
For 2) and 3) I tried several things but failed 
For example if the QTreeView is not set as a view for the combo box, I can use the signal clicked(), but this is not working with the view set on the combo box. If I use the combo's currentIndexChanged() signal, selecting item 2 will return index 0, because item 2 is a child of item 1 at index 0. I'm really confused about this model/view thing
Bookmarks