PDA

View Full Version : add widget on a TableWidget error!



xiongxiongchuan
16th June 2010, 09:45
i add a comobox on a TableWidget cells ,i used the for loop and the comobox only add on the last cell of the loop,and the others can't be edit! what's wrong ?




table=new QTableWidget(50,50,this);



QHBoxLayout *layou=new QHBoxLayout;
layou->addWidget(table);

setLayout(layou);
QComboBox *combox=new QComboBox;
combox->addItem("Text1",1);
combox->addItem("Text2",1);
combox->addItem("Text3",1);
combox->addItem("Text4",1);
combox->addItem("Text5",1);
combox->addItem("Text6",1);
combox->addItem("Text7",1);



for (int i=0;i<table->columnCount();i++)
{
table->setCellWidget(0,i,combox);

}T

high_flyer
16th June 2010, 10:32
you are adding the same combobox again and again.
You need to create a new combobox for each cell.