srazi
14th November 2010, 06: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);
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);