again problem in add items in tablewidget
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
Re: again problem in add items in tablewidget
Invoke QTableWidget::setRowCount() OR QTableWidget::insertRow(), not both. Variable
"int RowCount" is initialized as zero and never changed.
Code:
int row=tableWidget->rowCount();
tableWidget->insertRow(row);
tableWidget->setItem(row,0,item);
tableWidget->setItem(row,1,item1);
Re: again problem in add items in tablewidget
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
Re: again problem in add items in tablewidget
Code:
// initialize a checkable 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 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.