PDA

View Full Version : qevent problem



amulya
13th October 2006, 06:32
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:
bool CPreviewLeftWidget::eventFilter(QObject *obj, QEvent *event)
{
if (obj == m_plblIconInfo) {
if (event->type() == QEvent::HoverEnter)
{
CToolTip::showTip(m_plblIconInfo,tr("PreviewLeftWidget_Manual_Positioning_Heading"),tr("PreviewLeftWidget_Manual_Positioning_Tooltip"));
m_bHovered = TRUE;
return true;
}
if(event->type() == QEvent::HoverLeave)
{
CToolTip::onMouseLeave();
m_bHovered = FALSE;
return true;
}

else {
// pass the event on to the parent class
return QWidget::eventFilter(obj, event);
}
}
}

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:

void CToolTip::showTip(QWidget* widget,QString heading,QString tip)
{
if(m_pGlobalToolTip == NULL )
m_pGlobalToolTip = new CToolTip(widget,heading,tip);

m_pGlobalToolTip->setToolTip(heading, tip);

if(widget == NULL )
{
return;
}
QRect rect = widget->rect();
QPoint point = widget->mapToGlobal(widget->rect().topLeft());
int rect_height = rect.height();
int rect_width = rect.width();

int tooltip_width = m_pGlobalToolTip->getWidth();

int xpos;
int ypos;

if(m_pGlobalToolTip->isShownOnRight(widget))
{
xpos = point.x() + rect_width + 5 ;
if(xpos < 0)
xpos = 0;

ypos = point.y() + (rect_height/2) - 26 - CORNER_RADIUS;
if(ypos < 0)
ypos = 0;
}
else
{
xpos = point.x() - tooltip_width - 5;
if(xpos < 0)
xpos = 0;

ypos = point.y() + (rect_height/2) - 26 - CORNER_RADIUS;
if(ypos < 0)
ypos = 0;
}


QPoint pos(xpos, ypos);
m_pGlobalToolTip->showToolTip(pos);
}


QPainterPath CToolTip::getRoundPath(QRect rc)
{
int x1, y1, x2, y2;
rc.getCoords(&x1, &y1, &x2, &y2);

QPainterPath roundPath;

if(m_bShowRight)
{
roundPath.moveTo(x2, y1+CORNER_RADIUS);
roundPath.arcTo(x2-CORNER_RADIUS, y1, CORNER_RADIUS, CORNER_RADIUS, 0.0, 90.0);
roundPath.lineTo(x1+CORNER_RADIUS,y1);
roundPath.arcTo(x1+ARROW, y1, CORNER_RADIUS, CORNER_RADIUS, 90.0, 90.0);
roundPath.lineTo(x1+ARROW, y1+20);
roundPath.lineTo(x1, y1+20+6);
roundPath.lineTo(x1+ARROW, y1+20+6+6);
roundPath.lineTo(x1+ARROW, y2-CORNER_RADIUS);
roundPath.arcTo(x1+ARROW, y2-CORNER_RADIUS, CORNER_RADIUS, CORNER_RADIUS, 180.0, 90.0);
roundPath.lineTo(x1+CORNER_RADIUS, y2);
roundPath.arcTo(x2-CORNER_RADIUS, y2-CORNER_RADIUS, CORNER_RADIUS, CORNER_RADIUS, 270.0, 90.0);
roundPath.closeSubpath();
}
else
{
roundPath.moveTo(x2-ARROW, y1+CORNER_RADIUS);
roundPath.arcTo(x2-CORNER_RADIUS-ARROW, y1, CORNER_RADIUS, CORNER_RADIUS, 0.0, 90.0);
roundPath.lineTo(x1+CORNER_RADIUS,y1);
roundPath.arcTo(x1, y1, CORNER_RADIUS, CORNER_RADIUS, 90.0, 90.0);
roundPath.lineTo(x1, y2-CORNER_RADIUS);
roundPath.arcTo(x1, y2-CORNER_RADIUS, CORNER_RADIUS, CORNER_RADIUS, 180.0, 90.0);
roundPath.lineTo(x1+CORNER_RADIUS, y2);
roundPath.arcTo(x2-CORNER_RADIUS-ARROW, y2-CORNER_RADIUS, CORNER_RADIUS, CORNER_RADIUS, 270.0, 90.0);
roundPath.lineTo(x2-ARROW,y1+20+6+6);
roundPath.lineTo(x2,y1+20+6);
roundPath.lineTo(x2-ARROW,y1+20);
roundPath.lineTo(x2-ARROW,y1+CORNER_RADIUS);
roundPath.closeSubpath();
}

return roundPath;
}

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

high_flyer
13th October 2006, 09:07
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.

amulya
13th October 2006, 11:51
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