mytablewidget.cpp 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. #include "mytablewidget.h"
  2. MyTableWidget::MyTableWidget(QWidget *parent) : QTableWidget(parent)
  3. {
  4. this->setMouseTracking(true);
  5. lastrowbgcolor = QColor(0x00, 0xff, 0x00, 0x00);
  6. lastrow = -1;
  7. this->setStyleSheet("QHeaderView::section{border:0px solid white;background-color:white;}");
  8. this->verticalHeader()->setVisible(false);
  9. this->horizontalHeader()->setSectionResizeMode(QHeaderView::Stretch);
  10. this->setSelectionBehavior(QAbstractItemView::SelectRows);
  11. this->setShowGrid(false);
  12. this->setFocusPolicy(Qt::NoFocus);
  13. this->setEditTriggers(QAbstractItemView::NoEditTriggers);
  14. connect(this, SIGNAL(cellEntered(int,int)), this, SLOT(cellenterSlot(int, int)));
  15. }
  16. void MyTableWidget::cellenterSlot(int row, int col)
  17. {
  18. QTableWidgetItem *item = this->item(lastrow, 0);
  19. if (item != 0)
  20. {
  21. this->setRowColor(lastrow, lastrowbgcolor);
  22. }
  23. item = this->item(row, col);
  24. if (item != 0 && !item->isSelected())
  25. {
  26. this->setRowColor(row, QColor(222, 222, 222));
  27. }
  28. lastrow = row;
  29. }
  30. void MyTableWidget::leaveEvent(QEvent *event)
  31. {
  32. QTableWidgetItem *item = new QTableWidgetItem;
  33. item = this->item(lastrow, 0);
  34. if (item != 0)
  35. {
  36. this->setRowColor(lastrow, lastrowbgcolor);
  37. }
  38. }
  39. void MyTableWidget::setRowColor(int row, QColor color)
  40. {
  41. // for (int col = 0; col < this->columnCount(); col++)
  42. // {
  43. // QTableWidgetItem *item = this->item(row, col);
  44. // item->setBackgroundColor(color);
  45. // }
  46. }
  47. void MyTableWidget::updateClick(bool ok)
  48. {
  49. emit sigClick(ok);
  50. }