QToolTip not showing when QLineEdit is focused
-
Hey,
I have Subclassed QLineEdit and added focusInEvent and focusOutEvent like this
void QLineEditSubclass::focusInEvent(QFocusEvent *e) { QLineEdit::focusInEvent(e); emit(focused(true)); } void QLineEditSubclass::focusOutEvent(QFocusEvent *e) { QLineEdit::focusOutEvent(e); emit(focused(false)); }Focus slot is working, but QToolTip is not showing.
void Class::on_lineEdit_focused(bool focused) { QPoint pos = mapToGlobal(ui->lineEdit->pos()); qDebug() << pos; QToolTip::showText(pos, "Test text"); qDebug() << QToolTip::text(); qDebug() << QToolTip::isVisible(); }QDebug is printing pos and text of the QToolTip. isVisible returns false and QToolBox itself is not showing.
-
Hi,
Why not call setToolTip on your widget ?
-
Hi,
Why not call setToolTip on your widget ?
-
try adding the widget to the tooltip call
QToolTip::showText(pos, "Test text",this);From the docs:
The rect is in the coordinates of the widget you specify with w. If the rect is not empty you must specify a widget. Otherwise this argument can be 0 but it is used to determine the appropriate screen on multi-head systems.
-
try adding the widget to the tooltip call
QToolTip::showText(pos, "Test text",this);From the docs:
The rect is in the coordinates of the widget you specify with w. If the rect is not empty you must specify a widget. Otherwise this argument can be 0 but it is used to determine the appropriate screen on multi-head systems.
-
The QToolTip might not be the best tool then. Why do you need a permanent QToolTip ?
-
@SGaist
I need to have tooltip when qlineedit is focused to inform user about acceptable datatype, value range and small description.
I think I could make a special widget for this, which acts like tooltip. It could change location, text and visibility based on focused widget. -
@SGaist
I need to have tooltip when qlineedit is focused to inform user about acceptable datatype, value range and small description.
I think I could make a special widget for this, which acts like tooltip. It could change location, text and visibility based on focused widget.Hi.
something like this:
QLineEditSubclass::QLineEditSubclass(QWidget *parent) : QLineEdit(parent) { setToolTip("Test text"); } void QLineEditSubclass::focusInEvent(QFocusEvent *e) { QLineEdit::focusInEvent(e); auto gPos = (parentWidget()) ? parentWidget()->mapToGlobal(pos()) : pos(); auto toolTipEvent = new QHelpEvent(QEvent::ToolTip, pos(), gPos); QApplication::postEvent(this, toolTipEvent); }Not tested... :)