我发现可以通过以下方式在QLineEdit上设置工具提示:
equation = new QLineEdit();
equation->setToolTip("Example: a*b+c+~c");
然而,我希望当焦点在QLineEdit上时显示工具提示。我该怎么做呢?
提前感谢。
我发现可以通过以下方式在QLineEdit上设置工具提示:
equation = new QLineEdit();
equation->setToolTip("Example: a*b+c+~c");
我能够通过子类化QLineEdit并重写focusInEvent(...)来实现这一点:
void EquationEditor::focusInEvent(QFocusEvent *e)
{
QHelpEvent *event = new QHelpEvent(QEvent::ToolTip,
QPoint(this->pos().x(), this->pos().y()),
QPoint(QCursor::pos().x(), QCursor::pos().y()));
QApplication::postEvent(this, event);
QLineEdit::focusInEvent(e);
}
void QApplication::focusChanged ( QWidget * old, QWidget * now ) [signal]
这里还有一些关于Focus的非常好的信息:QFocusEvent Class Reference
希望它能对你有所帮助!