#include "mytablewidget.h" MyTableWidget::MyTableWidget(QWidget *parent) : QTableWidget(parent) { this->setMouseTracking(true); lastrowbgcolor = QColor(0x00, 0xff, 0x00, 0x00); lastrow = -1; this->setStyleSheet("QHeaderView::section{border:0px solid white;background-color:white;}"); this->verticalHeader()->setVisible(false); this->horizontalHeader()->setSectionResizeMode(QHeaderView::Stretch); this->setSelectionBehavior(QAbstractItemView::SelectRows); this->setShowGrid(false); this->setFocusPolicy(Qt::NoFocus); this->setEditTriggers(QAbstractItemView::NoEditTriggers); connect(this, SIGNAL(cellEntered(int,int)), this, SLOT(cellenterSlot(int, int))); } void MyTableWidget::cellenterSlot(int row, int col) { QTableWidgetItem *item = this->item(lastrow, 0); if (item != 0) { this->setRowColor(lastrow, lastrowbgcolor); } item = this->item(row, col); if (item != 0 && !item->isSelected()) { this->setRowColor(row, QColor(222, 222, 222)); } lastrow = row; } void MyTableWidget::leaveEvent(QEvent *event) { QTableWidgetItem *item = new QTableWidgetItem; item = this->item(lastrow, 0); if (item != 0) { this->setRowColor(lastrow, lastrowbgcolor); } } void MyTableWidget::setRowColor(int row, QColor color) { // for (int col = 0; col < this->columnCount(); col++) // { // QTableWidgetItem *item = this->item(row, col); // item->setBackgroundColor(color); // } } void MyTableWidget::updateClick(bool ok) { emit sigClick(ok); }