Nyphel
11th April 2007, 10:47
Hello,
I would like to add a QListWidget in a QTableWidget cell.
I know how to add checkboxes (simply set the cell item checked or unchecke, like this : Item_0->setCheckState(Qt::Checked); ) but I don't understand how to add other QListWidgets. For adding checkboxes, we simply modify the flags value of the QtableWidgetItem in the cell... But there isn't any flags concerning QlistWidgets.
Reading the QTableWidgetItem (http://doc.trolltech.com/4.2/qtablewidgetitem.html) documentation, they say :
Subclassing
When subclassing QTableWidgetItem to provide custom items, it is possible to define new types for them so that they can be distinguished from standard items. The constructors for subclasses that require this feature need to call the base class constructor with a new type value equal to or greater than UserType.
See also QTableWidget, Model/View Programming, QListWidgetItem, and QTreeWidgetItem.
And here (http://doc.trolltech.com/4.2/qtablewidgetitem.html#ItemType-enum) can be found the UserType documentation.
Is it the slution for adding QListWidgets in my QTableItems ?
If yes, could you explain me a bit more, please ? I don't understad very well what does it means :(
Thanks for your help :)
PS : Working code example :
void Table_impl::SLOT_add_row()
{
QListWidget *A_listWidget;
A_listWidget = new QListWidget(table);
QListWidgetItem *__item = new QListWidgetItem(A_listWidget);
__item->setText("Bla bla bla...");
table->setRowCount(table->rowCount() + 1);
QTableWidgetItem *Item_0 = new QTableWidgetItem();
QTableWidgetItem *Item_1 = new QTableWidgetItem("");
QTableWidgetItem *Item_2 = new QTableWidgetItem("");
QTableWidgetItem *Item_3 = new QTableWidgetItem("");
table->setItem(table->rowCount()-1, 0, Item_0);
//table->setItem(table->rowCount()-1, 1, Item_1);
table->setCellWidget(table->rowCount()-1, 1, A_listWidget);
table->setItem(table->rowCount()-1, 2, Item_2);
table->setItem(table->rowCount()-1, 3, Item_3);
Item_0->setCheckState(Qt::Unchecked);
Item_0->setFlags(Item_0->flags() & (~(Qt::ItemIsEditable)));
Item_1->setFlags(Item_1->flags() & (~(Qt::ItemIsEditable)));
Item_2->setFlags(Item_2->flags() & (~(Qt::ItemIsEditable)));
this->resize(table->width() + 4, this->height() + table->rowHeight(table->rowCount()-1));
}
.
I would like to add a QListWidget in a QTableWidget cell.
I know how to add checkboxes (simply set the cell item checked or unchecke, like this : Item_0->setCheckState(Qt::Checked); ) but I don't understand how to add other QListWidgets. For adding checkboxes, we simply modify the flags value of the QtableWidgetItem in the cell... But there isn't any flags concerning QlistWidgets.
Reading the QTableWidgetItem (http://doc.trolltech.com/4.2/qtablewidgetitem.html) documentation, they say :
Subclassing
When subclassing QTableWidgetItem to provide custom items, it is possible to define new types for them so that they can be distinguished from standard items. The constructors for subclasses that require this feature need to call the base class constructor with a new type value equal to or greater than UserType.
See also QTableWidget, Model/View Programming, QListWidgetItem, and QTreeWidgetItem.
And here (http://doc.trolltech.com/4.2/qtablewidgetitem.html#ItemType-enum) can be found the UserType documentation.
Is it the slution for adding QListWidgets in my QTableItems ?
If yes, could you explain me a bit more, please ? I don't understad very well what does it means :(
Thanks for your help :)
PS : Working code example :
void Table_impl::SLOT_add_row()
{
QListWidget *A_listWidget;
A_listWidget = new QListWidget(table);
QListWidgetItem *__item = new QListWidgetItem(A_listWidget);
__item->setText("Bla bla bla...");
table->setRowCount(table->rowCount() + 1);
QTableWidgetItem *Item_0 = new QTableWidgetItem();
QTableWidgetItem *Item_1 = new QTableWidgetItem("");
QTableWidgetItem *Item_2 = new QTableWidgetItem("");
QTableWidgetItem *Item_3 = new QTableWidgetItem("");
table->setItem(table->rowCount()-1, 0, Item_0);
//table->setItem(table->rowCount()-1, 1, Item_1);
table->setCellWidget(table->rowCount()-1, 1, A_listWidget);
table->setItem(table->rowCount()-1, 2, Item_2);
table->setItem(table->rowCount()-1, 3, Item_3);
Item_0->setCheckState(Qt::Unchecked);
Item_0->setFlags(Item_0->flags() & (~(Qt::ItemIsEditable)));
Item_1->setFlags(Item_1->flags() & (~(Qt::ItemIsEditable)));
Item_2->setFlags(Item_2->flags() & (~(Qt::ItemIsEditable)));
this->resize(table->width() + 4, this->height() + table->rowHeight(table->rowCount()-1));
}
.