PDA

View Full Version : createEditor() is not called in custom delegate



landstreicher
16th July 2010, 10:36
Hi,

i nearly searched all the web for this problem. My last chance is to post my problem here.

I need a tableWidget that contains multiple strings and checkboxes in one row. These checkboxes should change their value be clicking once.
So i created a delegate to customize a tableWidget. It almost does the things i needed, but when i change the triggers for editing the tableWidget to "SelectedClick" only, the delegate functions "createEditor","setEditor" and "setModelData" would not be called. The are called, if i double click the checkbox field, to enter editor mode, but that's not what i want.

So, does anyone have an hint?
Thanks.

For your information: Qt 4.6.3 on ubuntu and that little attached project is only a test to demonstrate my problem...

norobro
16th July 2010, 18:23
Try this:

Add the following to tab::tab (i.e. the constructor):
ui->tableWidget->setItemDelegateForColumn(2,new myTableDelegate());
ui->tableWidget->setItemDelegateForColumn(3,new myTableDelegate());
connect(ui->tableWidget,SIGNAL(cellClicked(int,int)),this,SLOT (cell_clicked(int, int)));
Remove these lines from tab:: on_bt_show_clicked():
//ui->tableWidget->setItemDelegate(new myTableDelegate());
// ui->tableWidget->setEditTriggers(QAbstractItemView::SelectedClicked );
//ui->tableWidget->setEditTriggers(QAbstractItemView::DoubleClicked | QAbstractItemView::SelectedClicked);
And create a custom slot:
void tab::cell_clicked(int row, int col) {
if(ui->tableWidget->item(row, col)->checkState() == Qt::Checked) ui->tableWidget->item(row, col)->setCheckState(Qt::Unchecked);
else ui->tableWidget->item(row, col)->setCheckState(Qt::Checked);
}

Be sure to declare the slot in "tab.h"

HTH

landstreicher
22nd July 2010, 02:50
ok, your hint makes it worse than before...
But now i use the "cellClicked(int,int)" signal from tableWidget and the custom tabledelgate, i wrote, is almost unnecessary...

Thanks a lot...

norobro
22nd July 2010, 04:41
ok, your hint makes it worse than before... How so?


But now i use the "cellClicked(int,int)" signal from tableWidget and the custom tabledelgate, i wrote, is almost unnecessary...
Correct. All you need is the paint method to draw checkboxes. Attached is a simple example.