PDA

View Full Version : Iterate and get Checked QTable items??



darpan
10th May 2006, 15:19
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

wysota
10th May 2006, 18:58
1) I want to iterate through the each columns items.

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());
}


2) I want to get no. of Checked items in first col and item also.

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);


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.

connect(table, SIGNAL(clicked(int, int, int, const QPoint &), table, SLOT(editCell(int, int)));


4) When i inserting using the above code then last row is inserted which only have checkbox.
I don't understand your question, sorry :)

chombium
10th May 2006, 19:27
Hi,

1.

iteration is very simple


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