1 Attachment(s)
createEditor() is not called in custom delegate
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...
Re: createEditor() is not called in custom delegate
Try this:
Add the following to tab::tab (i.e. the constructor):
Code:
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():
Code:
//ui->tableWidget->setItemDelegate(new myTableDelegate());
// ui->tableWidget->setEditTriggers(QAbstractItemView::SelectedClicked);
//ui->tableWidget->setEditTriggers(QAbstractItemView::DoubleClicked | QAbstractItemView::SelectedClicked);
And create a custom slot:
Code:
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
Re: createEditor() is not called in custom delegate
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...
1 Attachment(s)
Re: createEditor() is not called in custom delegate
Quote:
Originally Posted by
landstreicher
ok, your hint makes it worse than before...
How so?
Quote:
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.