lnxusr
21st November 2009, 00:32
I have a tablewidget where one item contains a checkbox. The state of the box is known when I create it like so:
QCheckBox *tblcbx= new QCheckBox();
m_ui->tableWidget->setCellWidget(row, 6, tblcbx);
if(m_ui->checkBox->isChecked())
tblcbx->setChecked(true);
My table is set to allow selection of entire row. I access the row via the itemSelectionChanged slot when a row is clicked on like so:
void Generate::on_tableWidget_itemSelectionChanged()
{
QList<QTableWidgetItem*> selected(m_ui->tableWidget->selectedItems());
QTableWidgetItem *item;
// Load the number boxes and string(list) with respective numbers..
foreach(item, selected)
{
Numbers[item->column()]->setText(item->text());
if(item->column() < 5)
WBNumbers << item->text();
}
PBNumber = selected[5]->text();
}
This works fine, and all items get to where they're supposed to go when a row is selected, but I can't for the life of me figure out how to read the checkstate of the checkbox in column 6.
On a similar note, how do I unselect rows in the tablewidget? Say, if the selected row was deleted, the widget will highlight the next or previous row. I don't want that. I want no rows highlighted after deletion, or when that row is clicked on again, it will unhighlight.
Also, is it possible to set it so only one row can be selected at a time (ie: holding down the CTRL key will not allow selecting two or more rows)?
QCheckBox *tblcbx= new QCheckBox();
m_ui->tableWidget->setCellWidget(row, 6, tblcbx);
if(m_ui->checkBox->isChecked())
tblcbx->setChecked(true);
My table is set to allow selection of entire row. I access the row via the itemSelectionChanged slot when a row is clicked on like so:
void Generate::on_tableWidget_itemSelectionChanged()
{
QList<QTableWidgetItem*> selected(m_ui->tableWidget->selectedItems());
QTableWidgetItem *item;
// Load the number boxes and string(list) with respective numbers..
foreach(item, selected)
{
Numbers[item->column()]->setText(item->text());
if(item->column() < 5)
WBNumbers << item->text();
}
PBNumber = selected[5]->text();
}
This works fine, and all items get to where they're supposed to go when a row is selected, but I can't for the life of me figure out how to read the checkstate of the checkbox in column 6.
On a similar note, how do I unselect rows in the tablewidget? Say, if the selected row was deleted, the widget will highlight the next or previous row. I don't want that. I want no rows highlighted after deletion, or when that row is clicked on again, it will unhighlight.
Also, is it possible to set it so only one row can be selected at a time (ie: holding down the CTRL key will not allow selecting two or more rows)?