Dropdown in Qtableview
-
I Want to add a drop down in a Qtableview at fixed a column and a row(1,1). drop down 3-4 values. And have to make one value as editable
tableview is not ui, have created using a Qtableview class.What are the approach , do implement this ?
I know one way is using Qcomboboxdelegate.Thankyou.
-
Hi,
So you want to have an editable QComboBox in a specific cell ?
-
I want a dropdown in a QTableview cell, drop down has 2 values like a and b, if user selects a then that is editable, but if b then non editable. When user selects a from drop down the cell content should set as a and user can edit that cell (Qtableview cell ) value, but if user selects b then cell is not editable.
-
@n-2204
This is not at all clear. (It is also very weird!)You want a dropdown to appear in a cell. That dropdown has 2 values,
a
andb
. User can select, by clicking, either value. If user selectsb
then "nothing special happens". But if user selectsa
what becomes editable? Thea
that the user has just selected?? Something else??Apart from the fact that it is hard to think of a case for this UI approach, it does not sound like it has anything to do with being in a
QTableView
cell. Take the combobox outside of the table and design whatever behaviour you say you want, get that working, before you worry about how to put it into a table. -
As I mentioned earlier, In a Qtableview cell I want to add a drop down option drop down contains two option like a ,b and basically a ,b, if user selects a then that cell will be editable it user select b then cell will be non editable this m doing for my calculation purpose , like b will have default data but if user want to change then change it to a an edit it.
If any suggestions plz mention. Thank you
-
And that on one specific cell ?
-
Then why not just position a QComboBox there and hide it once it has been used ?
-
Yes, since you only have that one combo box for that unique action.
-
@n-2204 said in Dropdown in Qtableview:
hide the QCombobox how to do that?
-
void QWidget::hide()
will hide the combobox from cell, and I have to show user the value of combobox selected by user like if combobox has 2 values when user selects a it is editable user can change it to t and if user selects b then its non editable and this value is set but if use hide then combobox will be hidden ? -
@n-2204 said in Dropdown in Qtableview:
if user selects b then its non editable and this value is set but if use hide then combobox will be hidden ?
Then show the selected value in a QLabel
-
how to replace value in combobox?
testdropdown::testdropdown(QWidget *parent) : QMainWindow(parent) { ui.setupUi(this); QStandardItemModel* stndrditem_model1 = NULL; QComboBox* combobox1; QStringList lst; if (stndrditem_model1 == NULL) { stndrditem_model1 = new QStandardItemModel(10, 11, this);//row*col } ui.tableView->setModel(stndrditem_model1); ui.tableView->setColumnWidth(2, 1); const QModelIndex idx = stndrditem_model1 ->index(1, 1); combobox1 = qobject_cast<QComboBox*>(ui.tableView->indexWidget(idx)); if (!combobox1) { combobox1 = new QComboBox(); ui.tableView->setIndexWidget(idx, combobox1); } lst<< "test" << "testdata"; combobox1->addItems(lst); connect(combobox1, QOverload<int>::of(&QComboBox::currentIndexChanged), this, &testdropdown::testedit); } void testdropdown::testedit(int indx) { if (indx == 1) { //when user select testdata combobox1->setEditable(true); //when user enter at index 1 the new data added at index 2 I want to replace at same index //how to replace testdata string list value with new value in combobox and index should remain same which is entered by user ?? } else{ combobox1->setEditable(false); } }