PDA

View Full Version : how to send a emulated mouse event to QListWidget



yxmaomao
21st July 2008, 03:25
I have a view based on QListWidget, Now I want to send a mouse double click event to my view to invoke view's mouse double click event.

Anybody tell me how to implement this function?

I am using Qt4.3 on XP

I have tried , qApp->postEvent(myView, [create my new double click event])
but my View can't get this double clicke event, why?

my function as below, this event is from one button,



void mouseDoubleClickEvent ( QMouseEvent * event )
{
QListWidget* pParent = qobject_cast< QListWidget*>(this->parent());
if ( NULL != pParent )
{
QMouseEvent* pNewMouseEvent = new QMouseEvent(event->type(),event->pos(),
event->button(),event->buttons(),
event->modifiers());
QEvent* pEvent = (QEvent*)(pNewMouseEvent);
if ( NULL != pEvent )
{
qApp->postEvent(pParent,pEvent);
}
//pParent->mouseDoubleClickEvent(event);
}
}



Thanks in advance

aamer4yu
21st July 2008, 07:08
Why are u trying to emulate the doubleclick event ??
Theres already QWidget::mouseDoubleClickEvent to use ? :confused:

jpn
21st July 2008, 19:34
qApp->postEvent(pParent->viewport(),pEvent);

yxmaomao
22nd July 2008, 01:41
Thanks jpn , you are right!

But I need send this event two times then my list vidget can get a real double click event, I don't know why?

Maybe you know.

yxmaomao
22nd July 2008, 03:49
Why are u trying to emulate the doubleclick event ??
Theres already QWidget::mouseDoubleClickEvent to use ? :confused:

hi, that's my special case