[Qt-interest] Mouse double click.

Shabd Swarup V shabd at cadence.com
Thu Feb 19 12:29:44 CET 2009


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?

Regards,
Shabd


-----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 4:16 PM
To: qt-interest at trolltech.com
Subject: Re: [Qt-interest] Mouse double click.

On 19.02.09 14:44:15, Shabd Swarup V wrote:
> Thanks for the response. I think the problem is slightly different.
> 
> I am not deriving from the QTreeView class but actually I am writing a
class that will do some operations on a particular QTreeView object.
> 
> For example, this is one of the methods in my class:

If you have the index for the item, than you can just use visualRect()
to
get the items rectangle. You might need to convert that from viewport to
widget coordinates (see QAbstractScrollArea api docs for the right
method)
and then you'll probably want to convert that to global coordinates
using
the treeview's mapToGlobal.

Andreas

-- 
Time to be aggressive.  Go after a tattooed Virgo.
_______________________________________________
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