Re: Qtablewidget Combobox
Hm. I'm not exactly sure how to fix this for a QTableWidget (though there is definitely a way), but I suggest that you forget about QTableWidget and take a look at QTableView and QSqlTableModel. They are part of the model/view framework and specifically meant for this sort of thing. Using custom widgets in certain columns will be easier that way.
Re: Qtablewidget Combobox
That really didnt halp...:(
We know the differances between the model and the item. We are just bring the data by a sql quary. The only problem is combobox does not apper in all the rows. İt just appers in a singe row.
Re: Qtablewidget Combobox
Why copy data from QSqlQuery to QTableWidgetItems when you could use QSqlQueryModel and QTableView? I suggest you take a look at the spinbox delegate example to get an idea how to provide custom editors.
Edit: As Michiel noticed, actually QSqlTableModel for an editable model of course.. :)
Re: Qtablewidget Combobox
Please be more specific about your problem. If you initiate an edit on one of the earlier rows (double-click), does the editor appear there then? Maybe you want all rows to have a visible combobox at the same time (not just during edit)? Then you want to open a persistent editor. See QTableWidget::openPersistentEditor(). If you do that, I think you also need a separate widget for each row. You can't use the same one for all of them at the same time.
If that's not what you mean, please explain more clearly.
And I still think you might want to use the Qt model/view framework instead of a QTableWidget. It's far more natural and robust that way. There's a model class specifically for Sql tables (QSqlTableModel).
Re: Qtablewidget Combobox
Have you put your code in a loop?
Re: Qtablewidget Combobox
Firstly, we normaly use models views istdead of item views. But we could use in this time, because every cell has an different behavier and also ever cells quaries from other cells. So we tought that it should be more easy to use item view.
For our problem, we SELECT make a quary like this,
void slottable()
{
row_of_table = 0;
id = "2";
QComboBox *newcombo;
newcombo = new QComboBox(this);
QSqlQuery Pindex;
Proformaindex.exec("SELECT ... FROM.... WHERE p_id = '" + id + "' ");
QSqlQuery kod;
kod.exec("SELECT id, kod FROM stk_kod");
while(stok_kod.next()) newcombo->addItem(kod.value(1).toString(), kod.value(0).toInt());
while(Pindex.next())
{
tableP->insertRow(row_of_table);
QTableWidgetItem *pr_id = new TableWidgetItem(Pindex.value(0).toString());
QTableWidgetItem *prof_id = new QTableWidgetItem(Pindex.value(1).toString());
QTableWidgetItem *profindex_turu = new QTableWidgetItem(Pindex.value(2).toString());
.
.
.
.
tableP->setItem(row_of_table, 0, pr_id);
tableP->setItem(row_of_table, 1, prof_id);
tableP->setItem(row_of_table, 2, profindex_turu);
.
tableProformaindex->setCellWidget(row_of_table, 1, newcombo);
row_of_table = row_of_table + 1;
}
tableP->resizeColumnToContents(0);
tableP->resizeColumnToContents(1);
}
The code is like this in simple, we would like to combo box to come when we would like to edit it. But acctually it comes to the last row and never goes from there.
Any way this what i could not do, if you could help me and save me from this desert i would be so happy!
Re: Qtablewidget Combobox
Now that I think about it, it's quite possible that the QTableWidget::setCellWidget() function makes the specified cell the new (and only) owner of the specified widget. This would explain why only the last row uses it.
So maybe you should only call that function when an editor is requested.
Re: Qtablewidget Combobox
Has the table been made sortable?
Re: Qtablewidget Combobox
Dear Michiel
How this is possible with the codes? And the is going to be other combo boxes other than this one?
Dear Jpn
No it not sortable!
Re: Qtablewidget Combobox
Quote:
Originally Posted by
aekilic
How this is possible with the codes?
I'm not really sure. Maybe you could reimplement QAbstractItemView::edit(). My first try would be to first set the cell widget and then call QAbstractItemView::edit(). But I've never tried this. I may be way off on this one.
Experiment a little. Search the docs.
Quote:
Originally Posted by
aekilic
And the is going to be other combo boxes other than this one?
Sorry, I don't know what you mean.
Re: Qtablewidget Combobox
I was telling there are going to be more combo boxes.
Re: Qtablewidget Combobox
Ah, but you used a question mark. :)
There will be more comboboxes. But, I assume, not at the same time. Only when an editor is requested (by a double-click trigger). Right?
Re: Qtablewidget Combobox
Yes, I would like to have the combo when i double clicked the item in the table!
Re: Qtablewidget Combobox
Quote:
Originally Posted by
aekilic
Yes, I would like to have the combo when i double clicked the item in the table!
Take a look at the spinbox delegate example as already suggested earlier in this thread.
Re: Qtablewidget Combobox
Dear All
Actually we have solved problem in a different way and we have added the combo different way. Thank you very much that you have helped us!
Re: Qtablewidget Combobox
Can you please share how you solved this problem....thanks
Re: Qtablewidget Combobox
try this you have to make a new object everytime.
for(int i=0; i<n; i++)
{
QComboBox * editor = new QComboBox(parent);
editor->addItem("0");
editor->addItem("1");
editor->addItem("Z");
editor->addItem("Last Known State");
io_ui->tableWidget->setCellWidget(i,j,editor);
}