My delegate class:
{
Q_OBJECT
public:
ComboBoxDelegate
(QObject *parent
= 0);
};
class ComboBoxDelegate : public QItemDelegate
{
Q_OBJECT
public:
ComboBoxDelegate(QObject *parent = 0);
QWidget *createEditor(QWidget *parent, const QStyleOptionViewItem &option,
const QModelIndex &index) const;
void setEditorData(QWidget *editor, const QModelIndex &index) const;
void setModelData(QWidget *editor, QAbstractItemModel *model,
const QModelIndex &index) const;
int indexOf(QString textToFind);
QSqlQueryModel *items;
};
To copy to clipboard, switch view to plain text mode
Initialise the delegate:
sqlClause = "SELECT cat_text, return_value FROM phone_codes"
" order by return_value";
phone_type_delegate->items->setQuery(sqlClause);
m_ui->phoneTableWidget->setItemDelegateForColumn(0,phone_type_delegate);
sqlClause = "SELECT cat_text, return_value FROM phone_codes"
" order by return_value";
phone_type_delegate->items->setQuery(sqlClause);
m_ui->phoneTableWidget->setItemDelegateForColumn(0,phone_type_delegate);
To copy to clipboard, switch view to plain text mode
Method to get selection:
{
}
void ClientDetailsDialog::onPhoneTableWidgetItemChanged(QTableWidgetItem* item)
{
QTableWidgetItem* item1 = m_ui->phoneTableWidget->item(item->row(), 0);
}
To copy to clipboard, switch view to plain text mode
I can get the combo box text from the above code, but I need to retrieve the index of the combobox selection.
I can do it like this:
int ComboBoxDelegate
::indexOf(QString textToFind
) {
int retVal = -1;
for (int x = 0; x < items->rowCount(); ++x)
{
if (items->data(items->index(x, 0)).toString() == textToFind)
{
retVal = x;
break;
}
}
return retVal;
}
int ComboBoxDelegate::indexOf(QString textToFind)
{
int retVal = -1;
for (int x = 0; x < items->rowCount(); ++x)
{
if (items->data(items->index(x, 0)).toString() == textToFind)
{
retVal = x;
break;
}
}
return retVal;
}
To copy to clipboard, switch view to plain text mode
Unless there's a simpler way of retrieving the index of the combo box, I'll have to settle for this solution. Nothing wrong with it, just figure there must be some method that simply gives the index.
Bookmarks