QT: How to show combo boxes as cells in a tree view
<p>In a designer-based QT GUI application I'm using a QTreeView to show a tree of elements that is provided by an instance of QStandardItemModel.
The tree-view is multi-column and all elements in the first column are checkable. The screenshot shows an example of how this currently looks like:
<a href="https://i.stack.imgur.com/AdHCg.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/AdHCg.png" alt="this is how the tree view currently looks like"></a></p>

<p>Now let's say I'd like the user to be able to select different names for "point". The idea is to have a QComboBox right next to each of the checkboxes. And as alternatives to "point" he may chose from a set of strings, e.g. "point", "pt" and "coord2D". Later on I'd like all selections for all duplicates of "point" to be synchronized but let's start simple...</p>

<p>I'm not too familiar with the idea but to me it looks like the way to go is to create an ItemDelegate for the view as described <a href="http://wiki.qt.io/Combo_Boxes_in_Item_Views" rel="nofollow noreferrer" title="QT Documentation">in the QT Documentation</a> or <a href="https://stackoverflow.com/questions/3135505/qstandarditem-qcombobox">in this topic</a> (both links refer to QTableWidgets instead of QTreeViews).</p>

<p>So what I did as a first step is I took the example delegate ComboBoxDelegate from the <a href="https://stackoverflow.com/questions/3135505/qstandarditem-qcombobox">stack overflow question mentioned above</a> and called it from within my application using this code also taken from a related question:</p>

<pre><code>QStandardItemModel* model = new QStandardItemModel(20,2);
ui.tvStructures-&gt;setModel(model);
ui.tvStructures-&gt;setItemDelegate(new ComboBoxDelegate());

for (int row = 0 ; row &lt; 20; ++row)
{
    for (int col = 0; col &lt; 2; ++col)
    {
        QModelIndex index = model-&gt;index(row, col, QModelIndex());
        model-&gt;setData(index, QVariant((row+1) * (col+1)));
    }
}
</code></pre>

<p>Note that I placed this code inside the constructor of the parent QDialog where the control element is located. What I ended up is a 2-column table as expected but without any combo boxes. In fact when debugging the code I observe that the constructor of the delegate is called (during the new operation) but none of createEditor, setEditorData, setModelData or updateEditorGeometry every get called. I thought this may be due to the fact that some connection magic is overwriting triggers required to do the drawing but even if I remove all code that refers to the tvStructures QTreeView apart from what I have posted I still can't see any combo boxes.</p>

<p>What's missing?</p>

<p>Note that I'm using the somewhat outdated QT 4.7.1</p>