Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. QToolTip Delay for seconds to show in QPlainTextEdit

QToolTip Delay for seconds to show in QPlainTextEdit

Scheduled Pinned Locked Moved Unsolved General and Desktop
2 Posts 2 Posters 2.0k Views 2 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • AmrCoderA Offline
    AmrCoderA Offline
    AmrCoder
    wrote on last edited by
    #1

    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 ?

    mrjjM 1 Reply Last reply
    0
    • AmrCoderA AmrCoder

      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 ?

      mrjjM Offline
      mrjjM Offline
      mrjj
      Lifetime Qt Champion
      wrote on last edited by
      #2

      @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

      1 Reply Last reply
      1

      • Login

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • Users
      • Groups
      • Search
      • Get Qt Extensions
      • Unsolved