Nominate our 2022 Qt Champions!

QToolTip Delay for seconds to show in QPlainTextEdit

  • I create a new class that inherit from QPlainTextEdit to implement a QToolTip which can show on words in this text this my class

    #include <QPlainTextEdit>
    #include <QDebug>
    #include <QObject>
    #include <QWidget>
    #include <QEvent>
    class PlainTextEdit : public QPlainTextEdit
      PlainTextEdit(QWidget *parent=0);
      bool event(QEvent *event); // this the event 
      void CursorChange(int n); // signal emit the current postion
      void SetString(QString s);
      QString str;
    #endif // PLAINTEXTEDIT_H


    #include "plaintextedit.h"
    #include <QToolTip>
    PlainTextEdit::PlainTextEdit(QWidget *parent):QPlainTextEdit(parent)
      str = "";
    bool PlainTextEdit::event(QEvent *event)
      if (event->type() == QEvent::ToolTip)
      QHelpEvent* helpEvent = static_cast<QHelpEvent*>(event);
      QTextCursor cursor = cursorForPosition(helpEvent->pos());;
      int i = cursor.anchor(); // the current mouse hover postion 
      emit CursorChange(i); // emit signal which i receive in the MainWindow and send back string in SetString Function
      if (!str.isEmpty()) {
      QToolTip::showText(helpEvent->globalPos(),str); // set string in tooltip to show
      str = "";
      return true;
      return QPlainTextEdit::event(event);
    // this function to set the string to show in tooltip
    void PlainTextEdit::SetString(QString s)
      str = s;
      qDebug() << "str = " << str;

    it should send the current cursor position pointed on by the mouse then emit this signal with the position and go to my MainWindow class make some code to extract this text then set the str variable which shows in the QToolTip part so is there any way to make it show faster it take time so I should hover on the word and stay second to show the QToolTip is there anything more efficient and faster ?

  • Lifetime Qt Champion

    As far as I know you cannot set the "trigger" delay.
    However you can activate it on will

Log in to reply