Results 1 to 5 of 5

Thread: Tooltip Displaying on the wrong position

  1. #1
    Join Date
    Feb 2012
    Posts
    10
    Thanked 2 Times in 1 Post
    Qt products
    Qt4
    Platforms
    Windows

    Default Tooltip Displaying on the wrong position

    Hi all,

    I have a weird issue. I'm trying to display a tooltip on a QPlainTextEdit subclass, and the tooltip is shown too much above the mouse cursor. I'm currently showing the word under the mouse cursor. I basically used the code here:
    http://developer.qt.nokia.com/faq/an...rd_in_a_qlabel

    Qt Code:
    1. bool logEditor::event(QEvent *event)
    2. {
    3. if (event->type() == QEvent::ToolTip)
    4. {
    5. processTooltip(static_cast <QHelpEvent*>(event)->pos(),static_cast <QHelpEvent*>(event)->globalPos());
    6. return true;
    7. }
    8.  
    9. return QPlainTextEdit::event(event);
    10. }
    11.  
    12. void logEditor::processTooltip(QPoint pos, QPoint globalpos)
    13. {
    14. QPoint adjustedPos=pos;
    15. adjustedPos.setX(adjustedPos.x()-lineNumberAreaWidth());
    16. QTextCursor cursor = cursorForPosition(adjustedPos);
    17. cursor.select(QTextCursor::WordUnderCursor);
    18. QToolTip::showText(globalpos, cursor.selectedText());
    19.  
    20. }
    To copy to clipboard, switch view to plain text mode 

    And see the result:
    screen.jpg

    The word displayed is the correct word, but the position is wrong...

  2. #2
    Join Date
    Feb 2008
    Posts
    491
    Thanks
    12
    Thanked 142 Times in 135 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11

    Default Re: Tooltip Displaying on the wrong position

    I'm not sure I understand what the problem is. From your screen shot it looks like the toolTip is shown in the standard position.

    Quote Originally Posted by nekkro-kvlt View Post
    . . . but the position is wrong...
    You can adjust the position. See QPoint::rx(). For example, to move it closer to the cursor vertically try this in processTootip():
    Qt Code:
    1. globalpos.ry() -= 5
    To copy to clipboard, switch view to plain text mode 

  3. #3
    Join Date
    Feb 2012
    Posts
    10
    Thanked 2 Times in 1 Post
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Tooltip Displaying on the wrong position

    Yes I know I can adjust it, but I was just wondering if i was doing something wrong, since afaik the global pos of the event should be right under the cursor ... Here I have a space of approx 1 cursor between the cursor and the tooltip...

    Also, do you know how to reduce the delay for the tooltip to show ?

    Thanks

  4. #4
    Join Date
    Feb 2008
    Posts
    491
    Thanks
    12
    Thanked 142 Times in 135 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11

    Default Re: Tooltip Displaying on the wrong position

    From QToolTip::showText():
    The tool tip will be shown with a platform specific offset from this point of interest.
    And from the source code:
    Qt Code:
    1. QPoint p = pos;
    2. p += QPoint(2,
    3. #ifdef Q_WS_WIN
    4. 21
    5. #else
    6. 16
    7. #endif
    8. );
    To copy to clipboard, switch view to plain text mode 
    Quote Originally Posted by nekkro-kvlt View Post
    Also, do you know how to reduce the delay for the tooltip to show ?
    Sorry, can't help with that.

  5. #5
    Join Date
    Feb 2012
    Posts
    10
    Thanked 2 Times in 1 Post
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Tooltip Displaying on the wrong position

    That Explain then, thanks !

Similar Threads

  1. Replies: 1
    Last Post: 8th April 2011, 19:54
  2. Replies: 4
    Last Post: 3rd May 2010, 11:41
  3. Replies: 7
    Last Post: 17th July 2009, 09:40
  4. mouseMoveEvent contains wrong position?
    By draftpunk in forum Qt Programming
    Replies: 10
    Last Post: 12th September 2008, 01:59
  5. Displaying tooltip for points in the graph
    By Ankitha Varsha in forum Qt Programming
    Replies: 4
    Last Post: 29th January 2008, 11:08

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.