I'm trying to create a custom class for QTableWidget where when clicking on a cell (or eventually just pressing the mouse down over a cell) it changes the background color.
This is what I have so far... it's fairly simple but it doesn't work yet and I'm not sure what I'm missing. Sorry, I'm new to the Qt environment.

Excerpt from mainwindow.cpp
Qt Code:
  1. int row = 10;
  2. int col = 10;
  3.  
  4. // set the amount of rows and columns
  5. ui->board->setRowCount(row);
  6. ui->board->setColumnCount(col);
  7.  
  8. // remove table headers
  9. ui->board->horizontalHeader()->setVisible(false);
  10. ui->board->verticalHeader()->setVisible(false);
  11.  
  12. // table styling
  13. ui->board->setFocusPolicy(Qt::NoFocus);
  14. ui->board->setSelectionMode(QAbstractItemView::NoSelection);
  15. // ui->board->setStyleSheet("selection-background-color: transparent");
  16. ui->board->setEditTriggers(QAbstractItemView::NoEditTriggers);
  17.  
  18. // set fixed column and row width
  19. for (int i = 0; i < row; i++)
  20. ui->board->setRowHeight(i, 50);
  21. for (int i = 0; i < col; i++)
  22. ui->board->setColumnWidth(i, 50);
  23.  
  24. // populate with items
  25. for (int i = 0; i < row; i++) {
  26. for (int j = 0; j < col; j++) {
  27. ui->board->setItem(i, j, new QTableWidgetItem);
  28. }
  29. }
To copy to clipboard, switch view to plain text mode 

excerpt from table.h
Qt Code:
  1. #include <QTableWidget>
  2. class Table : public QTableWidget
  3. {
  4. public:
  5. Table(QWidget *parent = nullptr) {}
  6.  
  7. Q_SIGNALS:
  8. void itemClicked(QTableWidgetItem *item);
  9.  
  10.  
  11. };
To copy to clipboard, switch view to plain text mode 

excerpt from table.cpp
Qt Code:
  1. #include "table.h"
  2.  
  3. void Table::itemClicked(QTableWidgetItem *item) {
  4. item->setBackground(Qt::red);
  5. }
To copy to clipboard, switch view to plain text mode