You should use QEvent::Enter
and QEvent::Leave
for better result.
Use next event filter:
In header:
protected:
bool eventFilter(QObject *obj, QEvent *event);
In constructor:
qApp->installEventFilter(this);
EventFilter:
bool MainWindow::eventFilter(QObject *obj, QEvent *event)
{
if (obj == ui->tableWidget && event->type() == QEvent::Enter)
{
qApp->setOverrideCursor(QCursor(Qt::ArrowCursor));
//or
qApp->setOverrideCursor(ui->tableWidget->cursor());
qDebug() << "added";
}
if (obj == ui->tableWidget && event->type() == QEvent::Leave)
{
qApp->restoreOverrideCursor();
}
return QObject::eventFilter(obj, event);
}
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…