QTableView, editable, 3 columns: QString, QWidget and QWidget
I'm trying to have an editable table of entries. Each entry has 3 columns.
The 1st is a choice of a string among a dynamic list of strings. So graphically, it should be a "pull-down menu"
The 2nd is, for the select string from the 1st column, there is a list of fields, values. I have a function that returns a QWidget that is made of QLabels and QLineEdits. I would like this QWidget to be in the 2nd column.
The 3rd column is a file path in a QLineEdit with a QPushButton.
The whole table is editable.
This QTableView uses a class derived from QAbstractTableModel. However I am unable to return QWidgets from the
Code:
QVariant data
(const QModelIndex
& index,
int role
) const
function.
What should I use when the cells of the table are complex widgets?
Regards,
Re: QTableView, editable, 3 columns: QString, QWidget and QWidget
You have to use delegates for that. See "Delegate Classes" and/or "An Introduction to Model/View Programming" in the documentation for a first start.
Re: QTableView, editable, 3 columns: QString, QWidget and QWidget
Thanks,
I am writing the
function of the delegate.
Column 0 is a non editable QComboBox where the user selects between a list of application objects represented by QStrings.
Columm 1 is an editable QWidget with (QLabels and QLineEdits). This cell depends on what is selected in the QComboBox.
There can be a different selection in the QComboBox for each row, of course.
This is the start of the implementation of createEditor:
Code:
{
switch(index.column()) {
case 0: {
systems_widget->setEditable(false);
for (....) /// pseudo code here
systems_widget
->addItem
( QString(someStdString.
c_str()) );
}
return systems_widget;
}
case 1:
return .... /// How do I pick up the selected item from the QComboBox in column 0 ?
case 2:
/// to implement
default:
return 0;
};
}
Re: QTableView, editable, 3 columns: QString, QWidget and QWidget
Hello,
My QTableView is basically in Edit mode all the time.
The returns a widget that is placed on top of the display widget for each cell when editing.
I don't need this.
Can I reuse the normal display widget (is there a default one?)
Rds,