How to set position of tooltip for qlabel?



  • Is it possible to set position of QTooltip at particular point of Dialog Screen in runtime, and display tooltip in left side?


  • Moderators

    Hi,

    "In the tooltips example ":http://qt-project.org/doc/qt-5.0/qtwidgets/widgets-tooltips.html

    You can set how to set/get positions.

    bq. QWidget::event() is the main event handler and receives all the widget's events. Normally, we recommend reimplementing one of the specialized event handlers instead of this function. But here we want to catch the QEvent::ToolTip events, and since these are rather rare, there exists no specific event handler. For that reason we reimplement the main event handler, and the first thing we need to do is to determine the event's type:

    @
    if (event->type() == QEvent::ToolTip) {
    QHelpEvent *helpEvent = static_cast<QHelpEvent *>(event);
    int index = itemAt(helpEvent->pos());
    if (index != -1) {
    QToolTip::showText(helpEvent->globalPos(), shapeItems[index].toolTip());
    } else {
    QToolTip::hideText();
    event->ignore();
    }

        return true;
    }
    return QWidget::event(event);
    

    }
    @

    bq. If the type is QEvent::ToolTip, we cast the event to a QHelpEvent, otherwise we propagate the event using the QWidget::event() function.

    hope it helps.



  • I doen'y understand position from that event handler, I just need to display tooltips in x,y position of screen. please specify meaning of @ QToolTip::showText(helpEvent->globalPos(), shapeItems[index].toolTip());@


Log in to reply
 

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