So, thing is, that was what I was using, but as suggested I switched to a listview. Now there is an equivalent function currentRow(), but the problem is the default for that is 0 when nothing is selected (as opposed to -1 for the combobox). Because of this, if I press OK without selecting anything, it still creates a new body (the 0th row option).TheMarkster wrote: ↑Fri Jul 30, 2021 2:50 am In a combobox you can use currentIndex() to find the currently selected item.
https://doc.qt.io/qt-5/qcombobox.html#currentIndex-prop
I'm now working around this by checking if the current row is selected, as so
Code: Select all
int idx = dlg.bodySelect->currentRow();
if (!dlg.bodySelect->item(idx)->isSelected()) {
return activeBody; // this is null at this point
}
That's one neat snippet!TheMarkster wrote: ↑Fri Jul 30, 2021 3:28 am To get the body that contains the active object currently selected:
Code: Select all
PartDesign::Body* bodyOfActiveObject = PartDesign::Body::findBodyOf(doc->getActiveObject());
I would like to know what those cases are, but the active object should be fine to get a working default most of the times.openBrain wrote: ↑Fri Jul 30, 2021 6:56 amTheMarkster already said it all (except I guess that 'activeObject' can be different from the selected item in some cases).
I quickly read the thread, and should say I would prefer a list rather than a combo box too. Especially if double-click is supported.
I'll see what I can do about the double click, but I'm not much experienced with Qt.