Please use "[CODE ]" tags when you post source code. Click the "#" button to add these tags.
bool TableData::filterSlot()
{
int columnCount = this->tablewidget->columnCount();
int rowCount = this->tablewidget->rowCount();
qDebug()<<"Count inside filter slot is";
qDebug()<<rowCount<<":"<<columnCount;
for(int c = 0; c<columnCount;c++)
{
for(int r = 0; r<rowCount;r++)
{
temp_string = this->tablewidget->item(r,c)->text();
if(!filterList.contains(temp_string))
filterList << temp_string;
}
filterList << "None";
combo->addItems(filterList);
combo->setCurrentIndex(filterList.count()-1);
this->tablewidget->setCellWidget(0,c,combo);
filterList.clear();
connect(combo,
SIGNAL(activated
(const QString &)),
this,
SLOT(testAnother
(const QString &)));
}
return true;
}
bool TableData::filterSlot()
{
int columnCount = this->tablewidget->columnCount();
int rowCount = this->tablewidget->rowCount();
QStringList filterList;
QString temp_string;
qDebug()<<"Count inside filter slot is";
qDebug()<<rowCount<<":"<<columnCount;
for(int c = 0; c<columnCount;c++)
{
for(int r = 0; r<rowCount;r++)
{
temp_string = this->tablewidget->item(r,c)->text();
if(!filterList.contains(temp_string))
filterList << temp_string;
}
filterList << "None";
combo = new QComboBox(tablewidget);
combo->addItems(filterList);
combo->setCurrentIndex(filterList.count()-1);
this->tablewidget->setCellWidget(0,c,combo);
filterList.clear();
connect(combo,SIGNAL(activated(const QString &)),this,SLOT(testAnother(const QString &)));
}
return true;
}
To copy to clipboard, switch view to plain text mode
Since every combobox is connected to the same slot, the only way you can determine which cell is responsible for the signal is to loop over the cells until you find a combobox that matches the one that sent the signal. Something like this:
void testAnother
( const QString & str
) {
int columnCount = this->tablewidget->columnCount();
int rowCount = this->tablewidget->rowCount();
int c = 0;
int r = 0;
bool bFound = false;
for( c = 0; c < columnCount; c++)
{
for( r = 0; r < rowCount; r++)
{
QWidget * cellWidget
= tableWidget
->cellWidget
( r, c
);
if ( cellWidget == senderWidget )
{
bFound = true;
break;
}
}
}
if ( bFound )
{
// do something with r, c
}
}
void testAnother( const QString & str )
{
QWidget * senderWidget = sender();
int columnCount = this->tablewidget->columnCount();
int rowCount = this->tablewidget->rowCount();
int c = 0;
int r = 0;
bool bFound = false;
for( c = 0; c < columnCount; c++)
{
for( r = 0; r < rowCount; r++)
{
QWidget * cellWidget = tableWidget->cellWidget( r, c );
if ( cellWidget == senderWidget )
{
bFound = true;
break;
}
}
}
if ( bFound )
{
// do something with r, c
}
}
To copy to clipboard, switch view to plain text mode
Bookmarks