这是一个简单demo,直接贴代码。
tablewidget.h
#ifndef TABLEWIDGET_H
#define TABLEWIDGET_H
#include <QTableWidget>
#include <QEvent>
class TableWidget : public QTableWidget
{
Q_OBJECT
public:
explicit TableWidget(QWidget *parent = 0);
protected:
void setRowColor(int row, QColor color);
signals:
public slots:
void mycellEntered(int row, int column);
private:
QTableWidget *tableWidget;
QColor defaultBkColor;
int previousColorRow;
};
#endif // TABLEWIDGET_H
tablewidget.cpp
#include "tablewidget.h"
#include <QMessageBox>
#include <QPoint>
TableWidget::TableWidget(QWidget *parent) :
QTableWidget(parent)
{
setGeometry(100,100,600,300);
defaultBkColor = QColor(255,255,255); //默认背景色
previousColorRow = -1;
tableWidget = new QTableWidget(this);
tableWid