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

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

    .cpp

    #include "plaintextedit.h"
    #include <QToolTip>
    
    
    PlainTextEdit::PlainTextEdit(QWidget *parent):QPlainTextEdit(parent)
    {
      setMouseTracking(true);
      str = "";
    }
    
    bool PlainTextEdit::event(QEvent *event)
    {
      if (event->type() == QEvent::ToolTip)
      {
      QHelpEvent* helpEvent = static_cast<QHelpEvent*>(event);
      QTextCursor cursor = cursorForPosition(helpEvent->pos());
      cursor.select(QTextCursor::WordUnderCursor);
      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 = "";
      }
      else
      QToolTip::hideText();
      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 ?


  • Qt Champions 2016

    @AmrCoder
    Hi
    As far as I know you cannot set the "trigger" delay.
    However you can activate it on will
    http://stackoverflow.com/questions/13720465/how-to-remove-the-time-delay-before-a-qtooltip-is-displayed


Log in to reply
 

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