1
votes

I have a QTableWidget instance with its cellEntered(int,int) signal associated to a slot X (that higlights the row in which the cell is contained). Also I have one column containing check boxes.

The problem is adding the checkboxes to the cells of the table using QTableWidget::setCellWidget() method:

QTableWidgetItem *checkBoxItem = new QTableWidgetItem("");
ui->tableWidget->setItem(rowCount, column, checkBoxItem);
QCheckBox* checkBox = new QCheckBox();
ui->tableWidget->setCellWidget(rowCount, column, checkBox);
connect(checkBox, SIGNAL(clicked(bool)),
    this, SLOT(checkbox_clicked(bool)));

makes the slot X not to be called when the cursor is over a cell in that column.

The problem is not particular for check boxes but for other types of widgets too.

I have read something about the SignalMapper class in some posts, but that class seems to be useful to map signal from the widget to a slot. Instead, my problem is relative to a signal from the table.

Any suggestion?

Cheers,

Pablo

1

1 Answers

0
votes

Why don't you use QTableWidgetItem and set it to checkable with QTableWidgetItem::setCheckState(Qt::CheckState state)?

QTableWidgetItem *check_item = new QTableWidgetItem;
check_item->setCheckState(Qt::Unchecked);

You can also do it with flags.

check_item->setFlags(Qt::ItemIsUserCheckable);

Connect QTableWidget::itemChanged(QTableWidgetItem * item) signal to a slot, and check if the item is checked there.