Results 1 to 3 of 3

Thread: qevent problem

  1. #1
    Join Date
    Mar 2006
    Posts
    19
    Thanks
    1

    Question qevent problem

    hi all,

    i m facing a strange problem. i have made a custom toolkit by doing some general drawing. The basic purpose is to show this tooltip when the mouse hovers over a widget and hide it when the cursor is removed off this widget. So, i showed the tooltip when the mouse hovers over the widget and hide it when the mouse is taken off it. Here is the code:
    Qt Code:
    1. bool CPreviewLeftWidget::eventFilter(QObject *obj, QEvent *event)
    2. {
    3. if (obj == m_plblIconInfo) {
    4. if (event->type() == QEvent::HoverEnter)
    5. {
    6. CToolTip::showTip(m_plblIconInfo,tr("PreviewLeftWidget_Manual_Positioning_Heading"),tr("PreviewLeftWidget_Manual_Positioning_Tooltip"));
    7. m_bHovered = TRUE;
    8. return true;
    9. }
    10. if(event->type() == QEvent::HoverLeave)
    11. {
    12. CToolTip::onMouseLeave();
    13. m_bHovered = FALSE;
    14. return true;
    15. }
    16.  
    17. else {
    18. // pass the event on to the parent class
    19. return QWidget::eventFilter(obj, event);
    20. }
    21. }
    22. }
    To copy to clipboard, switch view to plain text mode 

    The problem is that QHoverLeave event is sent even when the mouse is still over the widget...which causes a blinking effect. Here is the showTip and drawing used:
    Qt Code:
    1. void CToolTip::showTip(QWidget* widget,QString heading,QString tip)
    2. {
    3. if(m_pGlobalToolTip == NULL )
    4. m_pGlobalToolTip = new CToolTip(widget,heading,tip);
    5.  
    6. m_pGlobalToolTip->setToolTip(heading, tip);
    7.  
    8. if(widget == NULL )
    9. {
    10. return;
    11. }
    12. QRect rect = widget->rect();
    13. QPoint point = widget->mapToGlobal(widget->rect().topLeft());
    14. int rect_height = rect.height();
    15. int rect_width = rect.width();
    16.  
    17. int tooltip_width = m_pGlobalToolTip->getWidth();
    18.  
    19. int xpos;
    20. int ypos;
    21.  
    22. if(m_pGlobalToolTip->isShownOnRight(widget))
    23. {
    24. xpos = point.x() + rect_width + 5 ;
    25. if(xpos < 0)
    26. xpos = 0;
    27.  
    28. ypos = point.y() + (rect_height/2) - 26 - CORNER_RADIUS;
    29. if(ypos < 0)
    30. ypos = 0;
    31. }
    32. else
    33. {
    34. xpos = point.x() - tooltip_width - 5;
    35. if(xpos < 0)
    36. xpos = 0;
    37.  
    38. ypos = point.y() + (rect_height/2) - 26 - CORNER_RADIUS;
    39. if(ypos < 0)
    40. ypos = 0;
    41. }
    42.  
    43.  
    44. QPoint pos(xpos, ypos);
    45. m_pGlobalToolTip->showToolTip(pos);
    46. }
    To copy to clipboard, switch view to plain text mode 

    Qt Code:
    1. QPainterPath CToolTip::getRoundPath(QRect rc)
    2. {
    3. int x1, y1, x2, y2;
    4. rc.getCoords(&x1, &y1, &x2, &y2);
    5.  
    6. QPainterPath roundPath;
    7.  
    8. if(m_bShowRight)
    9. {
    10. roundPath.moveTo(x2, y1+CORNER_RADIUS);
    11. roundPath.arcTo(x2-CORNER_RADIUS, y1, CORNER_RADIUS, CORNER_RADIUS, 0.0, 90.0);
    12. roundPath.lineTo(x1+CORNER_RADIUS,y1);
    13. roundPath.arcTo(x1+ARROW, y1, CORNER_RADIUS, CORNER_RADIUS, 90.0, 90.0);
    14. roundPath.lineTo(x1+ARROW, y1+20);
    15. roundPath.lineTo(x1, y1+20+6);
    16. roundPath.lineTo(x1+ARROW, y1+20+6+6);
    17. roundPath.lineTo(x1+ARROW, y2-CORNER_RADIUS);
    18. roundPath.arcTo(x1+ARROW, y2-CORNER_RADIUS, CORNER_RADIUS, CORNER_RADIUS, 180.0, 90.0);
    19. roundPath.lineTo(x1+CORNER_RADIUS, y2);
    20. roundPath.arcTo(x2-CORNER_RADIUS, y2-CORNER_RADIUS, CORNER_RADIUS, CORNER_RADIUS, 270.0, 90.0);
    21. roundPath.closeSubpath();
    22. }
    23. else
    24. {
    25. roundPath.moveTo(x2-ARROW, y1+CORNER_RADIUS);
    26. roundPath.arcTo(x2-CORNER_RADIUS-ARROW, y1, CORNER_RADIUS, CORNER_RADIUS, 0.0, 90.0);
    27. roundPath.lineTo(x1+CORNER_RADIUS,y1);
    28. roundPath.arcTo(x1, y1, CORNER_RADIUS, CORNER_RADIUS, 90.0, 90.0);
    29. roundPath.lineTo(x1, y2-CORNER_RADIUS);
    30. roundPath.arcTo(x1, y2-CORNER_RADIUS, CORNER_RADIUS, CORNER_RADIUS, 180.0, 90.0);
    31. roundPath.lineTo(x1+CORNER_RADIUS, y2);
    32. roundPath.arcTo(x2-CORNER_RADIUS-ARROW, y2-CORNER_RADIUS, CORNER_RADIUS, CORNER_RADIUS, 270.0, 90.0);
    33. roundPath.lineTo(x2-ARROW,y1+20+6+6);
    34. roundPath.lineTo(x2,y1+20+6);
    35. roundPath.lineTo(x2-ARROW,y1+20);
    36. roundPath.lineTo(x2-ARROW,y1+CORNER_RADIUS);
    37. roundPath.closeSubpath();
    38. }
    39.  
    40. return roundPath;
    41. }
    To copy to clipboard, switch view to plain text mode 

    is this behaviour occuring cuz i do the drawing outside the widget's rectangle which causes QHoverLeave to occur...if this is so, how to stop it . I m on a tight deadline..so i would reallly appreciate a brisk reply or any kind of opinion!!!

    Regards,
    Amulya

  2. #2
    Join Date
    Jan 2006
    Location
    Munich, Germany
    Posts
    4,714
    Thanks
    21
    Thanked 418 Times in 411 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: qevent problem

    is this behaviour occuring cuz i do the drawing outside the widget's rectangle which causes QHoverLeave to occur...
    I just hover read your code, so I can't say for sure, but if the tooltip it self is under the cursor when it is shown, then it could be that it makes the hovered widget send the HoverLeave event since the cursor is now under the tooltip widget (once it is shown)....
    Make sure the toop tip is not dirrectly under the cursor when it is shown.

  3. #3
    Join Date
    Mar 2006
    Posts
    19
    Thanks
    1

    Question Re: qevent problem

    no, it wasnt the problem..the problem was that the tooltip class didnt have Qt::ToolTip attribute set..cuz of which it was sending out the leave events.

    anyways..thanx for ur reply..i really appreciate that

    Cheers,
    Amulya

Similar Threads

  1. Grid Layout Problem
    By Seema Rao in forum Qt Programming
    Replies: 2
    Last Post: 4th May 2006, 13:45
  2. Problem with receiving events from QDateEdit
    By gunhelstr in forum Qt Programming
    Replies: 4
    Last Post: 20th April 2006, 12:21
  3. Problem with bitBlt
    By yellowmat in forum Newbie
    Replies: 1
    Last Post: 5th April 2006, 15:08
  4. fftw problem
    By lordy in forum General Programming
    Replies: 1
    Last Post: 16th March 2006, 22:36
  5. Replies: 16
    Last Post: 7th March 2006, 16:57

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.