Results 1 to 3 of 3

Thread: Adding tooltips to canvas items

  1. #1
    Join Date
    Feb 2006
    Posts
    32
    Thanks
    3
    Qt products
    Qt4
    Platforms
    Unix/X11

    Smile Adding tooltips to canvas items

    Hi Every Body ,

    I want to add tooltip to canvas items. I know how to add tooltips to widget objects. As canvas items are not derived from QWidget, therefore not able to add to it.

    Needs all of your help.

    Regard & Thanks

  2. #2
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: Adding tooltips to canvas items

    Inherit Q3CanvasView and override:
    bool QWidget::event ( QEvent * e ) [virtual protected]

    You can show a dynamic tooltip like this:
    Qt Code:
    1. bool MyCanvasView::event(QEvent *event)
    2. {
    3. if (event->type() == QEvent::ToolTip) {
    4. QHelpEvent *helpEvent = static_cast<QHelpEvent*>(event);
    5. // compare event position and canvas item positions
    6. // and set tooltip text accordingly
    7. QToolTip::showText(helpEvent->globalPos(), "");
    8. }
    9. return QWidget::event(event);
    10. }
    To copy to clipboard, switch view to plain text mode 

  3. The following 2 users say thank you to jpn for this useful post:

    jnana (2nd March 2006), sunil.thaha (7th March 2006)

  4. #3
    Join Date
    Feb 2006
    Posts
    32
    Thanks
    3
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: Adding tooltips to canvas items

    Thanks JPN,

    It is working fine.

Similar Threads

  1. Replies: 5
    Last Post: 17th February 2009, 05:35
  2. Adding QGraphicsProxyWidget items into QGraphicsScene
    By yagabey in forum Qt Programming
    Replies: 3
    Last Post: 21st November 2008, 07:33
  3. When is the best time to delete a QCanvasItem
    By irudkin in forum Qt Programming
    Replies: 12
    Last Post: 8th March 2007, 22:28
  4. Limitation when adding more than 256 items to a model
    By darkadept in forum Qt Programming
    Replies: 5
    Last Post: 25th May 2006, 16:26
  5. [Qt4]: Adding centered items in QListWidget
    By Jojo in forum Qt Programming
    Replies: 4
    Last Post: 16th March 2006, 21:04

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.