I have a QTableWidget
widget in my application. I have to handle both single-click and double click mouse events separately in my application. Right now, only single-click slot is being called even when I double click on a cell. How do I handle them separately?
The following is the code for the signal-slot connection:
connect(ui.tableWidget, SIGNAL(cellClicked(int, int)), this, SLOT(myCellClicked(int, int)));
connect(ui.tableWidget, SIGNAL(itemDoubleClicked(QTableWidgetItem*)), this, SLOT(tableItemClicked(QTableWidgetItem*)));
Am I missing any other configuration here?
Okey, now i see. I had similar problem few weeks ago. The problem is in your QTableWidgetItem. I don't know exactly how does it work, but sometimes you can miss your item and click on cell. That's how you can fix it. Connect it this way:
connect(ui.tableWidget, SIGNAL(cellClicked(int, int)), this, SLOT(myCellClicked(int, int)));
connect(ui.tableWidget, SIGNAL(cellDoubleClicked(int,int)), this, SLOT(tableItemClicked(int,int)));
And in your tableItemClicked slot do it this way:
void MyWidget::tableItemClicked(int row, int column)
{
QTableWidgetItem *item = new QTableWidgetItem;
item = myTable->item(row,column)
/* do some stuff with item */
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With