[Qt-interest] Mouse double click.
Malyushytsky, Alex
alex at wai.com
Fri Feb 20 01:38:20 CET 2009
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."
More information about the Qt-interest-old
mailing list