1. 設(shè)置QTableView啟用鼠標(biāo)跟蹤:
ui->tableView->setMouseTracking(true);
2. 與QTableView的entered信號(hào)連接:
connect(ui->tableView, SIGNAL(entered(QModelIndex)),
this, SLOT(showToolTip(QModelIndex)));
3. 糟函數(shù):
void Widget::showToolTip(const QModelIndex &index) {
if (!index.isValid()) {
qDebug() << "Invalid index";
return;
}
QToolTip::showText(QCursor::pos(), index.data().toString() + "\ngoto hell");
}
QCursor::pos(): 返回鼠標(biāo)的位置.