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. Tooltip according to text background color or some other idea?

Tooltip according to text background color or some other idea?

Scheduled Pinned Locked Moved General and Desktop
3 Posts 2 Posters 2.5k Views 1 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.
  • A Offline
    A Offline
    abbassi
    wrote on last edited by
    #1

    Dear all,

    I am creating a main window and then putting a textbox there in my form. and then this is what I am trying to do as it was mentioned "here":http://qt-project.org/faq/answer/how_can_i_display_a_tooltip_over_only_one_word_in_a_qlabel and I am not getting any tooltip.

    @
    ui->recvEdit->append("CHECK\n");
    if (event->type() == QEvent::ToolTip)
    {
    QHelpEvent* helpEvent = static_cast <QHelpEvent*>(event);
    QTextCursor cursor = ui->recvEdit->cursorForPosition(helpEvent->pos());
    cursor.select(QTextCursor::WordUnderCursor);
    if (cursor.selectedText() == "CHECK")
    QToolTip::showText(helpEvent->globalPos(), cursor.selectedText());
    }
    @

    Also is it possible that i can use compare the font color or background color of my word instead of word.

    [Edit: Fixed URL in link and code formatting -- mlong]

    1 Reply Last reply
    0
    • G Offline
      G Offline
      goetz
      wrote on last edited by
      #2

      Do you get any text at all from the cursor? Are the coordinates correct? You will probably need to translate from global to local coordinates.

      http://www.catb.org/~esr/faqs/smart-questions.html

      1 Reply Last reply
      0
      • A Offline
        A Offline
        abbassi
        wrote on last edited by
        #3

        Thank you very much for the reply.
        No I am not getting any text as tooltip.
        I think they are correct because I am taking the current position of the cursor according to code.
        If you mean instead of passing in
        @ QToolTip::showText(helpEvent->globalPos(), cursor.selectedText());}@

        i should try passing local then i also did that but same result.

        here is the original code from where I am getting the idea. Maybe it will give you better understanding that what I am trying to achieve here.

        @#include <QtGui>

        class TextEdit : public QTextEdit
        {
        Q_OBJECT
        public:
        TextEdit(QWidget *parent) : QTextEdit(parent)
        {
        setTextInteractionFlags(Qt::TextBrowserInteraction);
        setFrameStyle(QFrame::NoFrame);
        setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
        setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
        setText("This application only provides a tooltip for the following word: polymorphism");
        QPalette pal = palette();
        pal.setColor(QPalette::Base, QColor(1, 0.941176, 0.941176, 0.941176) );
        setReadOnly(true);
        setPalette(pal);
        setFixedHeight(18);
        setFixedWidth(400);
        setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed);

            }
        
            bool event(QEvent* event) {
                    if (event->type() == QEvent::ToolTip)
                    {
                            QHelpEvent* helpEvent = static_cast <QHelpEvent*>(event);
                            QTextCursor cursor = cursorForPosition(helpEvent->pos());
                            cursor.select(QTextCursor::WordUnderCursor);
                            if (cursor.selectedText().startsWith("po" ))
                                QToolTip::showText(helpEvent->globalPos(), "Polymorphism");
                            else
                                    QToolTip::hideText();
                            return true;
                    }
        
                    return QTextEdit::event(event);
            }
        

        };@

        What i want is to use this
        @bool event(QEvent* event) {}@

        function in my code where i've already a textedit using form ui.
        Thanks in advance for the help.

        1 Reply Last reply
        0

        • Login

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