Results 1 to 8 of 8

Thread: Child QGraphicsItem setToolTip does not override parent QGraphicsItem's tooltip

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Jun 2008
    Location
    Boulder, Colorado, USA
    Posts
    70
    Qt products
    Qt5
    Platforms
    Unix/X11 Windows
    Thanks
    16
    Thanked 1 Time in 1 Post

    Default Re: Child QGraphicsItem setToolTip does not override parent QGraphicsItem's tooltip

    Thank you Franz. I did use the work "override" -- but I didn't mean that in the sense of C++ virtual methods. I'm not attempting to redefine QGraphicsItem::setToolTip() in any of my classes.

    I just want the child QGraphicsItem's "setToolTip" call to PREVAIL over the containing (parent's) "setToolTip" call when the mouse pointer is over the child QGraphicsItem.

    I did also make sure that the child QGraphicsItem had a higher "Z" value than the parent QGraphicsItem -- that didn't help. Only the tooltip text set by the parent's setToolTip call ever shows up.

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,373
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Thanks
    3
    Thanked 5,019 Times in 4,795 Posts
    Wiki edits
    10

    Default Re: Child QGraphicsItem setToolTip does not override parent QGraphicsItem's tooltip

    Please provide a minimal compilable example reproducing the problem.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  3. #3
    Join Date
    Jun 2008
    Location
    Boulder, Colorado, USA
    Posts
    70
    Qt products
    Qt5
    Platforms
    Unix/X11 Windows
    Thanks
    16
    Thanked 1 Time in 1 Post

    Default Re: Child QGraphicsItem setToolTip does not override parent QGraphicsItem's tooltip

    Well, QToolTips ARE working as desired in a simple example of nested QGraphicsItems. (See also screenshot of this example, below). I don't yet know why this isn't working in the context of our large application. THIS DOES WORK:

    Qt Code:
    1. // File: testGraphicItems.cpp
    2.  
    3. #include <QApplication>
    4. #include <QGraphicsScene>
    5. #include <QGraphicsView>
    6. #include <QGraphicsRectItem>
    7. #include <QGraphicsTextItem>
    8. #include <ostream>
    9.  
    10. int main(int argc, char** argv)
    11. {
    12. QApplication app (argc, argv);
    13. QGraphicsScene myScene;
    14.  
    15. // *******************************************
    16. // *** Create Outer Parent QGraphicsItem ***
    17. // *******************************************
    18.  
    19. QGraphicsRectItem* outerParentItem =
    20. new QGraphicsRectItem (-180.0, -70.0, 360.0, 140.0);
    21.  
    22. outerParentItem->setToolTip ("Parent Item ToolTip");
    23. outerParentItem->setFlags (QGraphicsItem::ItemIsMovable |
    24. QGraphicsItem::ItemIsSelectable);
    25.  
    26. myScene.addItem (outerParentItem);
    27.  
    28. // *******************************************
    29. // *** Create Inner Parent QGraphicsItem ***
    30. // *******************************************
    31.  
    32. QGraphicsRectItem* innerParentItem =
    33. new QGraphicsRectItem (-140.0, -45.0, 280.0, 90.0, outerParentItem);
    34.  
    35. // ************************************
    36. // *** Create Child QGraphicsItem ***
    37. // ************************************
    38.  
    39. QGraphicsTextItem* childItem =
    40. new QGraphicsTextItem ("Child QGraphicsTextItem", innerParentItem);
    41.  
    42. const QRectF childRect = childItem->boundingRect();
    43. childItem->setPos (-0.5 * childRect.width(), -0.5 * childRect.height());
    44.  
    45. childItem->setToolTip ("Child Item ToolTip");
    46.  
    47. // ******************************
    48. // *** Create QGraphicsView ***
    49. // ******************************
    50.  
    51. QGraphicsView myView (&myScene);
    52. myView.setCaption ("Test Nested QGraphicsItems ToolTips");
    53. myView.setAttribute (Qt::WA_AlwaysShowToolTips);
    54. myView.resize (420, 200);
    55. myView.show();
    56.  
    57. return app.exec();
    58. }
    59.  
    60. //--- (end testGraphicItems.cpp) ---
    To copy to clipboard, switch view to plain text mode 

    Here is a screenshot -- without showing the QToolTip. (That's a little tricky to capture using our X11 setup):



    BaseOK.gif

    Thank you.
    Last edited by philw; 29th November 2010 at 18:36.

  4. #4
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,373
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Thanks
    3
    Thanked 5,019 Times in 4,795 Posts
    Wiki edits
    10

    Default Re: Child QGraphicsItem setToolTip does not override parent QGraphicsItem's tooltip

    An example of working code is very unlikely to help us see the problem in the code that doesn't work.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  5. The following user says thank you to wysota for this useful post:

    philw (29th November 2010)

  6. #5
    Join Date
    Jun 2008
    Location
    Boulder, Colorado, USA
    Posts
    70
    Qt products
    Qt5
    Platforms
    Unix/X11 Windows
    Thanks
    16
    Thanked 1 Time in 1 Post

    Default Re: Child QGraphicsItem setToolTip does not override parent QGraphicsItem's tooltip

    Quote Originally Posted by wysota View Post
    An example of working code is very unlikely to help us see the problem in the code that doesn't work.
    Yes, of course. I just wanted to share this confirmation that Qt 4.6.3 IS working as I had hoped, in this particular respect. I'll take it from here. Thank you.

  7. #6
    Join Date
    Jul 2009
    Location
    Enschede, Netherlands
    Posts
    462
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows
    Thanked 69 Times in 67 Posts

    Default Re: Child QGraphicsItem setToolTip does not override parent QGraphicsItem's tooltip

    Good to see you've solved the issue.
    Horse sense is the thing that keeps horses from betting on people. --W.C. Fields

    Ask Smart Questions

  8. The following user says thank you to franz for this useful post:

    philw (29th November 2010)

Similar Threads

  1. QGraphicsItem::setToolTip does not work
    By Nadia in forum Qt Programming
    Replies: 2
    Last Post: 6th September 2009, 19:54
  2. Qgraphicsitem parent/child paint problem.
    By repka3 in forum Qt Programming
    Replies: 1
    Last Post: 24th July 2009, 22:03
  3. Casting QGraphicsItem child from QGraphicsItem
    By patrik08 in forum Qt Programming
    Replies: 3
    Last Post: 29th August 2008, 15:37
  4. Replies: 9
    Last Post: 22nd June 2008, 22:26
  5. QGraphicsItem tooltip behavior
    By darksaga in forum Qt Programming
    Replies: 6
    Last Post: 22nd August 2007, 17:50

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.