PDA

View Full Version : set ItemDelegate for QTableWidget(s) in QTabWidget(s)



srazi
14th November 2010, 07:59
Myapp has a QTabWidget, and every Tab has a QTableWidget.
I try to set MyItemDelegate on every table.

When I use following code:


for (int i = 0; i < mainTabWidget->count(); ++i)
{
CurrentTabWidget *tmp = getCurrentTabWidget(i);
QAbstractItemDelegate *tmpDelegate = tmp->table->itemDelegate();
if (tmpDelegate)
{
delete tmpDelegate;
tmpDelegate = 0;
}
tmp->table->setItemDelegate(new MyItemDelegate(CurrentTabWidget->table));
}

MyItemDelegate is set on every Tab, but for exampe:
if I open three tab and select second one and then close first then second one, I see current Tab (third one) has no itemDelegate (its items aren't painted)
what's wrong with this code?

The following code works perfectly:


int currentIndex = mainTabWidget->currentIndex();
for (int i = 0; i < mainTabWidget->count(); ++i)
{
mainTabWidget->setCurrentIndex(i);
//currentTab is a pointer to CurrentTabWidget within QTabWidget current Tab
QAbstractItemDelegate *tmpDelegate = currentTab->table->itemDelegate();
if (tmpDelegate)
{
delete tmpDelegate;
tmpDelegate = 0;
}
currentTab->table->setItemDelegate(new MyItemDelegate(currentTab->table));
}
mainTabWidget->setCurrentIndex(currentIndex);

ChrisW67
14th November 2010, 08:22
At line 10 of first code block, what is "CurrentTabWidget->table"?

srazi
14th November 2010, 09:54
At line 10 of first code block, what is "CurrentTabWidget->table"?

wow! thanks.
I think, I need a new glasses ;)