[Qt-interest] Mouse double click.

Shabd Swarup V shabd at cadence.com
Fri Feb 20 04:29:37 CET 2009


Hi,

I have so far tried 3 ways to achieve a double-click:

1. QTestEventList eventList;
   eventList.addMouseClick(Qt::LeftButton, 0, parentPosition);
   eventList.addMouseClick(Qt::LeftButton, 0, parentPosition);
   eventList.simulate(targetWidget);

2. QMouseEvent event(QEvent::MouseButtonDblClick, parentPosition,
globalPosition, Qt::LeftButton,0, 0);
   QCoreApplication::sendEvent(targetWidget, &event);

3. Sending press+release+press+release.

All these methods have the same result. They "select" that particular
index in the tree, i.e. it performs a single click only, although a
double-click is supposed to expand that index in the tree.

Thus, I am quite confident that the widget receives the event, but NOT a
double-click.

Also, what would be interesting to note is that using postEvent() throws
the following error on execution:
*** glibc detected *** double free or corruption (out):
0x0000007fbfffcca0 ***

Any suggestions on this?

Thanks for your help.

Regards,
Shabd

-----Original Message-----
From: qt-interest-bounces at trolltech.com
[mailto:qt-interest-bounces at trolltech.com] On Behalf Of Malyushytsky,
Alex
Sent: Friday, February 20, 2009 6:08 AM
To: qt-interest at trolltech.com
Subject: Re: [Qt-interest] Mouse double click.

I don't see how sending multiple events instead of
QEvent::MouseButtonDblClick may improve anything, but I see how you can
get in trouble with it.

Each system has its own settings, which affects the way single clicks
are treated - as a few single clicks or doubleclick. Such settings can
be cofigured by user, so there is no way to insure you will get double
click event by sending few single click events unless you really send it
the form of doubleclick or go and find such settings to determine the
most reasonable timing yourself.

Using postEvent in the most cases are safer, but it might be nothing
wrong to use sendEvent here. It is difficult to say cause we don't know
how the code below is executed.

What actually is not working?
Does widget receive event at all?
Is the item event sent for visible at the time event is sent?

Alex


-----Original Message-----
From: qt-interest-bounces at trolltech.com
[mailto:qt-interest-bounces at trolltech.com] On Behalf Of Andreas Pakulat
Sent: Thursday, February 19, 2009 3:40 AM
To: qt-interest at trolltech.com
Subject: Re: [Qt-interest] Mouse double click.

On 19.02.09 16:59:44, Shabd Swarup V wrote:
> Hi Guys,
>
> I'm sure you're aware of my problem by now :)
>
> This is what I've tried to do after your suggestions:
>
> {
>         QWidget* targetWidget = targetObject->viewport();
>
>         //Get QRect for the given index.
>         const QRect indexRect = targetObject->visualRect(index);
>
>         //Get position relative to parent widget.
>         const QPoint parentPosition =
> targetObject->mapToParent(QPoint(indexRect.x(),indexRect.y()));
>
>         //Get global position.
>         const QPoint globalPosition =
> targetWidget->mapToGlobal(QPoint(indexRect.x(),indexRect.y()));
>
>         //Create mouseevent for double click.
>         QMouseEvent event(QEvent::MouseButtonDblClick, parentPosition,
> globalPosition, Qt::LeftButton,0, 0);
>
>         //Send event to the widget.
>         QCoreApplication::sendEvent(targetWidget, &event);
> }
>
> It's not working :( What am I doing wrong?

I suggest to use postEvent, not sendEvent. Also you probably shouldn't
send
a double-click like this, but rather press+release+press+release. Qt
will
then translate that into a double-click.

Andreas

--
You are fighting for survival in your own sweet and gentle way.
_______________________________________________
Qt-interest mailing list
Qt-interest at trolltech.com
http://lists.trolltech.com/mailman/listinfo/qt-interest


------------------------------------------------------------------------
---------------------------
Weidlinger Associates, Inc. made the following annotations.

"This message and any attachments are solely for the intended recipient
and may contain confidential or privileged information. If you are not
the intended recipient, any disclosure, copying, use, or distribution of
the information included in this message and any attachments is
prohibited. If you have received this communication in error, please
notify us by reply e-mail and immediately and permanently delete this
message and any attachments. Thank you."

"Please consider our environment before printing this email."

_______________________________________________
Qt-interest mailing list
Qt-interest at trolltech.com
http://lists.trolltech.com/mailman/listinfo/qt-interest




More information about the Qt-interest-old mailing list