Results 1 to 3 of 3

Thread: tool tip for canvasitems

  1. #1
    Join Date
    Aug 2006
    Location
    istanbul, turkey
    Posts
    42
    Thanks
    2
    Thanked 4 Times in 4 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11

    Default tool tip for canvasitems

    I'm trying to build a tooltipbox for qcanvas which is similar to QToolTip object.

    i have a qcanvaspolygonalitem subclass objects displayed in qcanvasview. mouseTracking for qcanvasview is enabled. so i capture all mouseMoveEvents.When mouse pointer comes over one of the qcanvaspolygonalitem's bounding rect my tooltipbox object is shown and if pointer is out of all qcanvaspolygonalitems then this object should be hidden. i also added moving capability to qcanvaspolygonalitems using QWMatrix.

    the problem is "when moving is started then hidden tooltipbox is shown without any show command(i hope so)"

    i'll provide code snipplet below;

    Note:
    my ToolTip object is also polygonalitem.

    thanks anyway,

    Qt Code:
    1. void MyCanvasView::contentsMouseMoveEvent ( QMouseEvent * e )
    2. {
    3. QPoint p = e->pos();
    4. QCanvasItemList l = m_pCanvas->allItems();
    5. SomePolygonalItem* pSomePolygonalItem = 0;
    6.  
    7. // if mouse is pressed then moving is true
    8. if ( moving ) {
    9. for( QCanvasItemList::iterator it = l.begin(); it != l.end(); it++){
    10. (*it)->moveBy(p.x() - moving_start.x(), p.y() - moving_start.y());
    11. }
    12.  
    13. moving_start = p;
    14. m_pCanvas->setAllChanged();
    15. }
    16. else {
    17. for( QCanvasItemList::iterator it = l.begin(); it != l.end(); it++){
    18. if ((*it)->rtti() == SomePolygonalItem::RTTI && (*it)->boundingRect().contains(p) ) {
    19. pSomePolygonalItem = (SomePolygonalItem*) (*it);
    20. break;
    21. }
    22. }
    23.  
    24. if pSomePolygonalItem {
    25. // toString is a member function of SomePolygonalItem
    26. // setText is member function of ToolTip object
    27. m_pToolTip->setText( pSomePolygonalItem->toString() );
    28. m_pToolTip->setX(p.x());
    29. m_pToolTip->setY(p.y());
    30. m_pToolTip->show();
    31. }
    32. else {
    33. m_pToolTip->hide();
    34. }
    35. }
    36.  
    37.  
    38. m_pCanvas->update();
    39. }
    To copy to clipboard, switch view to plain text mode 
    Last edited by jacek; 9th August 2006 at 13:31. Reason: added code tags

  2. #2
    Join Date
    Aug 2006
    Location
    istanbul, turkey
    Posts
    42
    Thanks
    2
    Thanked 4 Times in 4 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11

    Default Re: tool tip for canvasitems

    guys, when i statically set all tooltips' text to the same string, then every thing goes ok. Strange???

  3. #3
    Join Date
    Aug 2006
    Location
    istanbul, turkey
    Posts
    42
    Thanks
    2
    Thanked 4 Times in 4 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11

    Default Re: tool tip for canvasitems

    ok, i found the solution now. I realized that; if tooltip objects's texts are the same then everything works ok. But when i change them dynamically then it becomes a disaster. Finallay i choose not to have only one tooltip for all canvas items, but to create a tooltip for each canvasitems. then everthing becomes ok now.


Similar Threads

  1. What are your favourite C++ books?
    By eugen in forum General Programming
    Replies: 84
    Last Post: 12th January 2021, 16:47
  2. Hide the border of a tool bar?
    By Dark_Tower in forum Qt Programming
    Replies: 6
    Last Post: 20th August 2007, 14:04
  3. tool tip for label
    By Seema Rao in forum Qt Programming
    Replies: 1
    Last Post: 21st April 2006, 13:22
  4. Facing problem with tool bar icons
    By jnana in forum Qt Programming
    Replies: 4
    Last Post: 20th April 2006, 08:37
  5. tool bar icon size looking small???
    By darpan in forum Qt Tools
    Replies: 7
    Last Post: 31st March 2006, 16:38

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.