Show tooltip under mouse cursor



  • Hello all!!

    I would like to show a tooltip exactly under the mouse cursor ( and i've done it), but it disappear immediately and it seems that is calling the leaveEvent of the widget that has created the tooltip.
    It happen even if i don't move the mouse cursor.

    Any suggestion please?

    Many thanks



  • How about creating your own ToolTip and use its methods showText & hideText based on anything you want - mouse movement, timer.


  • Lifetime Qt Champion

    Hi and welcome to devnet,

    How are you doing your tooltip ?



  • Many thanks for your answers,
    here the code used at the moment.

    @class myview : public QTreeView {

    bool viewportEvent(QEvent * event) {

    if (event->type() == QEvent::ToolTip) {

    QHelpEvent *helpEvent = static_cast<QHelpEvent *>(event);
    QModelIndex index = indexAt(helpEvent->pos());

    QRect r(visualRect(index));
    QString tipText(index.data(0).toString());

    if (r.width() >= fontMetrics().width(tipText)) {
    event->ignore();
    QToolTip::hideText();
    return true;
    }
    else {

    QPoint p = r.topLeft();
    

    p -= QPoint(2,
    #ifdef Q_WS_WIN
    21
    #else
    16
    #endif
    );
    event->accept();
    QToolTip::showText(mapToGlobal(p), tipText);
    return true;
    }
    }
    return QTreeView::viewportEvent(event);
    }

    ...

    ...

    }@

    Create my own tool tip class is not easy for me and take long time.
    Maybe there is another way.

    Thanks


  • Lifetime Qt Champion

    What about handling the Qt::ToolTipRole in your model ?


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.