Here is an example code where all three signals are emitted.

Make a note of this

1. When mouse left cliecked -> cellClicked() is emitted.
2. When mouse left double clicked -> cellClicked() and cellDoubleClicked() is emitted.
3. When mouse right clicked -> cellClicked() and customContextMenuRequested() is emitted.

QTableWidget.jpg
Qt Code:
  1. #include <QtGui>
  2. #include <QApplication>
  3.  
  4. class Widget : public QTextBrowser
  5. {
  6. Q_OBJECT
  7.  
  8. public:
  9. explicit Widget(QTableWidget * table)
  10. {
  11. connect(table, SIGNAL(cellDoubleClicked(int, int)), this, SLOT(tableChangeDbl(int, int)));
  12. connect(table, SIGNAL(cellClicked(int, int)), this, SLOT(tableChange(int, int)));
  13.  
  14. table->setContextMenuPolicy(Qt::CustomContextMenu);
  15. connect(table, SIGNAL(customContextMenuRequested(const QPoint &)), this, SLOT(PopupMenuTableShow(const QPoint &)));
  16. show();
  17. }
  18.  
  19. public slots:
  20. void tableChange(int row, int column)
  21. {
  22. append(QString("Clicked %1, %2").arg(row).arg(column));
  23. }
  24.  
  25. void tableChangeDbl(int row, int column)
  26. {
  27. append(QString("Double Clicked %1, %2").arg(row).arg(column));
  28. }
  29.  
  30. void PopupMenuTableShow(const QPoint & point)
  31. {
  32. append(QString("Menu %1, %2").arg(point.x()).arg(point.y()));
  33. }
  34. };
  35.  
  36. int main(int argc, char **argv)
  37. {
  38. QApplication app(argc, argv);
  39.  
  40. QTableWidget tableWidget;
  41. Widget widget(&tableWidget);
  42.  
  43. tableWidget.setRowCount(10);
  44. tableWidget.setColumnCount(2);
  45. for(int r = 0 ; r < tableWidget.rowCount(); r++)
  46. for(int c = 0 ; c < tableWidget.columnCount(); c++)
  47. tableWidget.setItem(r, c, new QTableWidgetItem(QString("%1:%2").arg(r).arg(c)));
  48.  
  49. tableWidget.setWindowTitle("QTableWidget");
  50. widget.setWindowTitle("Widget");
  51.  
  52. tableWidget.show();
  53. widget.show();
  54.  
  55. return app.exec();
  56. }
  57.  
  58. #include "main.moc"
To copy to clipboard, switch view to plain text mode