PDA

View Full Version : again problem in add items in tablewidget



jyoti
24th November 2006, 08:48
hi all
i wanna add items in tablewidget on one buttonclick
like when i click button then item both items item n item1 shud enter at one click...
bt if i follow the following way then t first enter the item1,then item
and next is after opening i didnt get the check button....under column 0
plz do suggest me..wht to do nw


void form5::addItem()
{
int row=0;
int RowCount=0;
row=tableWidget->rowCount();
tableWidget->setRowCount(row+1);
QTableWidgetItem *item=new QTableWidgetItem("abc");
item->setFlags(Qt::ItemIsSelectable | Qt::ItemIsEnabled |Qt::ItemIsUserCheckable);
tableWidget->setItem(RowCount,0,item);

QTableWidgetItem *item1=new QTableWidgetItem("123");
tableWidget->insertRow(row);
tableWidget->setItem(RowCount,1,item1);


TIA

jpn
24th November 2006, 09:18
Invoke QTableWidget::setRowCount() OR QTableWidget::insertRow(), not both. Variable
"int RowCount" is initialized as zero and never changed.


int row=tableWidget->rowCount();
tableWidget->insertRow(row);

QTableWidgetItem *item=...
tableWidget->setItem(row,0,item);

QTableWidgetItem *item1=...
tableWidget->setItem(row,1,item1);

jyoti
24th November 2006, 10:24
thanks for rplying...its helpful...
n can u tell how we can show checkbox which having property QT::ItemIsUserCheckable
i mean when user checked it then another form should be opened

jpn
24th November 2006, 13:03
// initialize a checkable item
QTableWidgetItem* item = ...
item->setFlags(item->flags() | Qt::ItemIsUserCheckable);
item->setCheckState(Qt::Unchecked);


To react to check state changes, connect to signal QTableWidget::itemChanged(). This signal is emitted whenever the data of an item has changed. The corresponding item is passed as a parameter. Check it's check state and do corresponding actions. Just be aware that the signal is emitted whenever any data of the items changes, it has not necessarily been a change of the check state.

QTableWidget nor any QAbstractItemView descendant class offers any signal which would inform only check state changes. To only react to check state changes, Trolltech suggests (http://www.trolltech.com/developer/task-tracker/index_html?id=110172&method=entry) you to reimplement QTableWidgetItem::setData().

PS. once again this has nothing to do with Qt Designer which is a tool for designing and building graphical user interfaces.