PDA

View Full Version : How to suppress cellClicked() signal from QTableWidget item



rawfool
20th June 2013, 15:18
For some particular QTableWidgetItem items, I need to suppress the cellClicked(int, int) signal or I need to disable that item. Is there any way that I can easily do it.
Thank you.

Santosh Reddy
20th June 2013, 15:35
Do you want to disable the clickable option of the item, then set the appropriate flag for the item.

If you want to just supress the cellClicked() then it is not possible, you will have to handle that in the connected slot, by identifying the item by row and col.

rawfool
20th June 2013, 15:50
Yeah, disable clickable option will do.

I tried,
setCurrentCell(nRow, nCol, QItemSelectionModel::NoUpdate) But in my slot, I'm still find the cellClicked() signal for that cell getting emitted.
BTW, I'm having a Icon for those cells which I'm going to click, I'm setting the icon using setItem(nRow, nCol, new QTableWidgetItem(QIcon(":/imgs/updateIcon.png"), ""); Will that cause any problem?

I need to disable clickable option some particular cells. Thank you.

wysota
20th June 2013, 16:01
QTableWidgetItem::setFlags()

Santosh Reddy
20th June 2013, 16:03
BTW, I'm having a Icon for those cells which I'm going to click, I'm setting the icon using setItem(nRow, nCol, new QTableWidgetItem(QIcon(":/imgs/updateIcon.png"), ""); Will that cause any problem?

First be clear of what you want.
1. Do you want the item/icon to be clickable and not emit the signal
You cannot stop/supress the signal, you can only filter it out in the slot.

2.Do you want the item not to be clickable
If yes, then use item's API to disable click

QTableWidgetItem::setFlags(flags() & ~Qt::ItemIsSelectable)



My aim is to disable some particular cells. Thank you.
Hmm, now you want to disable

QTableWidgetItem::setFlags(flags() & ~Qt::ItemIsEnabled)

rawfool
20th June 2013, 16:25
Thank you Wysota & Santosh,

If I click on a particular cell, I don't want cellClicked() signal from that cell. I'm trying to give more info what I've done here by saying that cell has got an icon also.

If disable doesn't emit, cellClicked signal, then it's good for me. I tried to set above said flags, I was still able to see my debug messages in my slot for cellClicked signal.

Santosh Reddy
20th June 2013, 18:17
If you are still not able to disable the item, please show us what you did.

wysota
20th June 2013, 18:18
Forget cellClicked(), focus on the goal you wish to achieve.

rawfool
21st June 2013, 07:01
CResultsTbl is a table.


// cresultstbl.cpp ( Class name: CResultsTbl)
void CResultsTbl::loadData()
{
if(s == "true")
{
setItem(nRow, Remediate_Col,
new QTableWidgetItem(QIcon(":/imgs/fixIcon.png"), ""));
}
else if(s == "false")
{
setItem(nRow, Remediate_Col,
new QTableWidgetItem(QIcon(":/imgs/tick.png"), ""));
item(nRow, Remediate_Col)->setFlags(item(nRow, Remediate_Col)->flags() & ~Qt::ItemIsEnabled);
}
else
{
setItem(nRow, Remediate_Col, new QTableWidgetItem());
item(nRow, Remediate_Col)->setFlags(item(nRow, Remediate_Col)->flags() & ~Qt::ItemIsEnabled);
}
}

For the else if(s == "false") and else, I don't want to add the data into map (inCReportsPage class)
In CReportsPage, I'm creating objects, of CResultsTbl and processing


// vulnTable, patchTable are objects of CResultsTbl
void CReportsPage::onCellClicked(int nRow, int nCol)
{
if(nCol == CResultsTable::Remediate_Col)
{
switch (tabWidget->currentIndex())
{
case 0:
// The below debug message getting printed even for the false case in the above code (cresultstbl.cpp)
qDebug() << vulnTable->item(nRow, CResultsTable::Id_Col)->text();
remIndiv_Map[vulnTable->item(nRow, CResultsTable::Id_Col)->text()] =
vulnTable->item(nRow, CResultsTable::Reference_Col)->text();
break;
case 1:
qDebug() << "Patch Table";
remIndiv_Map[patchTable->item(nRow, CResultsTable::Id_Col)->text()] =
patchTable->item(nRow, CResultsTable::Reference_Col)->text();
break;
case 2:
qDebug() << "Compliance Table";
remIndiv_Map[complTable->item(nRow, CResultsTable::Id_Col)->text()] =
complTable->item(nRow, CResultsTable::Reference_Col)->text();
break;
default:
break;
}

if(!indivRem_BatchTimer->isActive())
{
indivRem_BatchTimer->start(5000);
}

}
}

wysota
21st June 2013, 09:19
You don't want to add the data into what map?

rawfool
21st June 2013, 09:26
Kindly check my comment in the code. Thank you for helping.

switch (tabWidget->currentIndex())
{
case 0:
// The below debug message getting printed even for the false case in the above code (cresultstbl.cpp)
qDebug() << vulnTable->item(nRow, CResultsTable::Id_Col)->text();



// vv
// Here I'm copying the clicked cell's row data into a QMap (remIndiv_Map)
remIndiv_Map[vulnTable->item(nRow, CResultsTable::Id_Col)->text()] = vulnTable->item(nRow, CResultsTable::Reference_Col)->text();
// ^^
break;
.....
....
}

And I don't have the data of which ones are not to be copied, in CReportsPage

void CResultsTbl::loadData()
{
if(s == "true")
{
....
}
// here itself I need to filter data which I'm going to add to QMap (CReportsPage::remIndiv_Map) on click of the cell
else if(s == "false")
{
setItem(nRow, Remediate_Col,
new QTableWidgetItem(QIcon(":/imgs/tick.png"), ""));
item(nRow, Remediate_Col)->setFlags(item(nRow, Remediate_Col)->flags() & ~Qt::ItemIsEnabled);
}
}

Santosh Reddy
21st June 2013, 11:15
Why are you switch(ing) switch (tabWidget->currentIndex()), you shoud switch for row.

tabWidget->currentIndex() will return QModelIndex not row number. Row number is a parameter of the slot.

rawfool
21st June 2013, 11:33
I'm using switch to find the active table in my QTabWidget on which user is clicked the cell. I have 3 tables in my QTabWidget.
And in a table, I have column called "Fix Issue", where all the cells will have either "Yes" or "Done". So If user clicks on a cell which has "Yes" or "Done", the values are put into QMap for further processing.

So, here I don't need values of the row of cell which has got "Done", even if users clicks tht cell, I should not add that cell's row data into QMap

Santosh Reddy
21st June 2013, 12:14
Then show us where and how are you are disabling the item?

I don't think loadData() is called when user clicks on "Yes" item.

You will have to disable the item in cellClicked() connected slot.

[EDIT] Looks like cellClicked() is emitted even if item is disabled.

You can check if the item is enabled before adding it the map.