Results 1 to 6 of 6

Thread: How can we set tooltip to a particular area of widget?

  1. #1
    Join Date
    Aug 2011
    Location
    Bangalore, India
    Posts
    23
    Qt products
    Qt3 Qt4
    Platforms
    MacOS X Windows Symbian S60

    Question How can we set tooltip to a particular area of widget?

    Suppose half of the area of widget we want to display tooltip and half area dont want to display. how can we do that?Is there any predefined function.

  2. #2
    Join Date
    May 2010
    Location
    Romania
    Posts
    1,021
    Thanks
    62
    Thanked 260 Times in 246 Posts
    Qt products
    Qt5
    Platforms
    MacOS X Unix/X11 Windows Android

    Default Re: How can we set tooltip to a particular area of widget?

    I don't think you can do that, and i can't imagine why you would want to do it.

    But what you can do is create your own "widget" (by deriving from QWidget or create it into the designer) and there you can have for example: a QLabel (with it's own tooltip) and a QLineEdit also with it's own tooltip... or two QLabel's and only one has a tooltip...

    Also you can tell us more about what are you trying to achieve and maybe some of us have better ideas.

  3. #3
    Join Date
    Aug 2011
    Location
    Bangalore, India
    Posts
    23
    Qt products
    Qt3 Qt4
    Platforms
    MacOS X Windows Symbian S60

    Question Re: How can we set tooltip to a particular area of widget?

    I am creating a userdefined tooltip class and it has one function called class::add(Qwidget *w, QRect, Qstring);. I am passing following to the add fuction of the class while calling -address of object to which i want to set tooltip to QWidget pointer and Qrect is the rectangle portion of that object which i want to set tool tip and string is the tooltip text.
    So my problem is that how to implement this tooltip class so that tooltip will be displayed only when the mouse pointer is inside that object rect. Actually i want to work all this when i call add function of tooltip class for any other widget.

  4. #4
    Join Date
    Jan 2008
    Location
    Alameda, CA, USA
    Posts
    5,323
    Thanks
    316
    Thanked 871 Times in 858 Posts
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: How can we set tooltip to a particular area of widget?

    Since I was just talking about event filters in another thread, it is still in my mind.

    Tool tips are invoked through QHelpEvent types (in other words, QEvent::ToolTip uses a QHelpEvent instance). QHelpEvent contains the x, y position of the cursor. So, install an event filter on your widget, and examine the position to see if it is contained within the rect. If it is inside the rect, then you return "false" from the filter (which allows the event to go on to the widget), otherwise return "false" and the event is eaten.

    If you make your user-defined tooltip class flexible enough, you could have multiple tool tips on a widget, each with its own rect. So, for example, if your widget is displaying a map, you could pop up a different tool tip for each city.

  5. #5
    Join Date
    Aug 2011
    Location
    Bangalore, India
    Posts
    23
    Qt products
    Qt3 Qt4
    Platforms
    MacOS X Windows Symbian S60

    Default Re: How can we set tooltip to a particular area of widget?

    Quote Originally Posted by d_stranz View Post
    Since I was just talking about event filters in another thread, it is still in my mind.

    Tool tips are invoked through QHelpEvent types (in other words, QEvent::ToolTip uses a QHelpEvent instance). QHelpEvent contains the x, y position of the cursor. So, install an event filter on your widget, and examine the position to see if it is contained within the rect. If it is inside the rect, then you return "false" from the filter (which allows the event to go on to the widget), otherwise return "false" and the event is eaten.

    If you make your user-defined tooltip class flexible enough, you could have multiple tool tips on a widget, each with its own rect. So, for example, if your widget is displaying a map, you could pop up a different tool tip for each city.

    can you please give a brief code example for it. Does QHelpevent can be used to know the position of cursor of parent window in child window.

  6. #6
    Join Date
    Jan 2008
    Location
    Alameda, CA, USA
    Posts
    5,323
    Thanks
    316
    Thanked 871 Times in 858 Posts
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: How can we set tooltip to a particular area of widget?

    Read the docs. QHelpEvent has both global and widget coordinates. QWidget has mapFromGlobal() / mapToGlobal() and mapFromParent() / mapToParent() to translate point positions from any widget to any other widget.

    Sorry, but I don't have a code example. This is not a hard problem to solve.

Similar Threads

  1. Using QPainter to 'erase' an area of widget?
    By altec42lansing in forum Qt Programming
    Replies: 13
    Last Post: 17th June 2011, 16:19
  2. How to get an area of the widget transparent...???
    By kapoorsudhish in forum Qt for Embedded and Mobile
    Replies: 1
    Last Post: 5th March 2010, 04:20
  3. update(), aber not erase the the widget's area?
    By blm in forum Qt Programming
    Replies: 1
    Last Post: 26th September 2008, 15:26
  4. Tooltip-like widget
    By momesana in forum Qt Programming
    Replies: 5
    Last Post: 4th October 2007, 18:33
  5. Moving Tooltip out of cursor-area
    By afo in forum KDE Forum
    Replies: 1
    Last Post: 7th January 2006, 15:13

Tags for this Thread

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
  •  
Qt is a trademark of The Qt Company.