Iterate and get Checked QTable items??
Hi,
I am working on QTable and QTableItem. I have a table containing three columns(Name, Extension, Size) . I am inserting checkable item in col first and Extension is readonly and Size col is editable. I am using QT 3.3.5. I am using the following code for the table item insertion:-
int j=0;
int k=0;
table1->setItem( j, 0, new QCheckTableItem( table1, Name ) );
table1->setItem( k, 1, new QTableItem( table1, QTableItem::Never,ExtensionName ) );
j++;
k++;
Now My problem is that
1) I want to iterate through the each columns items.
2) I want to get no. of Checked items in first col and item also.
3) Third column is editable but when i double click on this column then only the cursor for editing appears, how i can do this on single click and give focus to edit.
4) When i inserting using the above code then last row is inserted which only have checkbox.
Best Regards
Re: Iterate and get Checked QTable items??
Quote:
Originally Posted by darpan
1) I want to iterate through the each columns items.
Code:
for(int i=0;i<table->numRows();i++){
QTableItem *item = table->item(i, 0);
qDebug("Column 0 of item %d says '%s'", i, item->text().latin1());
}
Quote:
2) I want to get no. of Checked items in first col and item also.
Code:
uint itemschecked = 0;
for(int i=0;i<table->numRows();i++){
QTableItem *item = table->item(i, 0);
QCheckTableItem *checkitem = dynamic_cast<QCheckTableItem*>(item);
if(checkitem && checkitem->isChecked()) itemschecked++;
}
qDebug("Total of %d items checked", itemschecked);
Quote:
3) Third column is editable but when i double click on this column then only the cursor for editing appears, how i can do this on single click and give focus to edit.
Code:
connect(table,
SIGNAL(clicked
(int,
int,
int,
const QPoint &), table,
SLOT(editCell
(int,
int)));
Quote:
4) When i inserting using the above code then last row is inserted which only have checkbox.
I don't understand your question, sorry :)
Re: Iterate and get Checked QTable items??
Hi,
1.
iteration is very simple
Code:
for (i=0; i< table->numRows(); i++)
for(j=0; j < table->numCols(); j++)
{
// do something with the table
}
the above code goes through every cell of the table
2.
if ((QComboBox*)table->cellWidget( i, j))->isChecked() cnt++;
cnt = counter of checked items
i, j = row and column of the cell
3.
in the clicked signal handler
void QTable::clicked ( int row, int col, int button, const QPoint & mousePos ) [signal]
set cell editing to by using the editCell() function
http://doc.trolltech.com/3.3/qtable.html#editCell
or connect the the clicked signal to cellEdit slot
4.
check the setCellWidget() function
http://doc.trolltech.com/3.3/qtable.html#setCellWidget
chombium