I 'm subclassing the QSqlRelationalDelegate and I have this (working) python code which I 'm trying to convert to Qt c++:
def createEditor(self, parent, option, index):
# column of combo box 'position'
positionColumn = 2
print("myDelegate.createEditor index.column()=" + str(index.column()) + " option=" + str(option) )
if index.column() == positionColumn:
editor.model().select()
return editor
else:
return super(myDelegate, self).createEditor(parent, option, index)
def createEditor(self, parent, option, index):
# column of combo box 'position'
positionColumn = 2
print("myDelegate.createEditor index.column()=" + str(index.column()) + " option=" + str(option) )
if index.column() == positionColumn:
editor = QSqlRelationalDelegate.createEditor(self, parent, option, index)
if isinstance(editor, QComboBox):
editor.model().select()
return editor
else:
return super(myDelegate, self).createEditor(parent, option, index)
To copy to clipboard, switch view to plain text mode
What I 've done so far (don't take it as correct, it's just an effort, it's not working):
{
int positionColumn = 2;
qDebug()<< "BookDelegate.createEditor index.column()=" << (index.column()) << " option=" << option ;
if (index.column() == positionColumn){
//QComboBox *editor = new QComboBox(parent);
//QSqlRelationalTableModel *model = qobject_cast <QSqlRelationalTableModel*>(index.model());
///QComboBox* myCombo = qobject_cast <QComboBox*>(editor);
editor->model()->select();
return editor;
}
QWidget *BookDelegate::createEditor(QWidget *parent,
const QStyleOptionViewItem &option,
const QModelIndex &index) const
{
int positionColumn = 2;
qDebug()<< "BookDelegate.createEditor index.column()=" << (index.column()) << " option=" << option ;
if (index.column() == positionColumn){
QWidget *editor = QSqlRelationalDelegate::createEditor(parent, option, index);
//QComboBox *editor = new QComboBox(parent);
//QSqlRelationalTableModel *model = qobject_cast <QSqlRelationalTableModel*>(index.model());
///QComboBox* myCombo = qobject_cast <QComboBox*>(editor);
editor->model()->select();
return editor;
}
To copy to clipboard, switch view to plain text mode
Any help is welcome.
Bookmarks