Trolltech Home | Qt-interest Home | Recent Threads | All Threads | Author | Date
All threads index page 2

Qt-interest Archive, July 2007
How to get the object on which mouse is released?


Message 1 in thread

Hi All,

I have a small doubt here.

How to get the object on which mouse is released?

 

In my code I am performing a mousePressEvent on a button(say button1)
and mouseReleaseEvent on another button(say button2). The problem here
is I am not able to access the button on which mouseReleaseEvent is
performed (ie .not able to access button2) instead it is referring to
button1.

 

 

I tried with the below code but it is not working.

 

Void mouseReleaseEvent(QMouseEvent *event)

 

{

            If(event->button==4)

{

 

            QString str;

 

            str=this->text();

 

Printf("str : %s\n",str.toLatin1().data());

 

}

 

}

 

But in the above code "this pointer" is referring to the object on which
the mousePressEvent happened. so how to get the object on which the
mouse is released?

 

 

Regards

Naveen

 




The information contained in this electronic message and any attachments to this message are intended for the exclusive use of the addressee(s) and may contain proprietary, confidential or privileged information. If you are not the intended recipient, you should not disseminate, distribute or copy this e-mail. Please notify the sender immediately and destroy all copies of this message and any attachments. 

WARNING: Computer viruses can be transmitted via email. The recipient should check this email and any attachments for the presence of viruses. The company accepts no liability for any damage caused by any virus transmitted by this email.
 
www.wipro.com

Message 2 in thread

      QApplication::widgetAt ( const QPoint
      <http://zorro/developpement/documentation/qt4.2.2/html/qpoint.html>
      & /point/ )   [static]


QApplication::widgetAt(event->globalPos());




naveen.kmrvm@xxxxxxxxx a écrit :

> Hi All,
>
> I have a small doubt here.
>
> *How to get the object on which mouse is released?*
>
>  
>
> In my code I am performing a mousePressEvent on a button(say button1) 
> and mouseReleaseEvent on another button(say button2). The problem here 
> is I am not able to access the button on which mouseReleaseEvent is 
> performed (ie .not able to access button2) instead it is referring to 
> button1.
>
>  
>
>  
>
> I tried with the below code but it is not working.
>
>  
>
> Void mouseReleaseEvent(QMouseEvent *event)
>
>  
>
> {
>
>             If(event->button==4)
>
> {
>
>  
>
>             QString str;
>
>  
>
>             str=this->text();
>
>  
>
> Printf("str : %s\n",str.toLatin1().data());
>
>  
>
> }
>
>  
>
> }
>
>  
>
> But in the above code *"this pointer" is referring to the object on 
> which the mousePressEvent happened*. so how to get the object on which 
> the mouse is released?
>
>  
>
>  
>
> Regards
>
> Naveen
>
>  
>
>
> The information contained in this electronic message and any 
> attachments to this message are intended for the exclusive use of the 
> addressee(s) and may contain proprietary, confidential or privileged 
> information. If you are not the intended recipient, you should not 
> disseminate, distribute or copy this e-mail. Please notify the sender 
> immediately and destroy all copies of this message and any attachments.
>
> WARNING: Computer viruses can be transmitted via email. The recipient 
> should check this email and any attachments for the presence of 
> viruses. The company accepts no liability for any damage caused by any 
> virus transmitted by this email.
>
> www.wipro.com
>


Message 3 in thread

 

But QApplication::widgetAt(event->globalPos()) function returns a QWidget but I want a QPushButton so that I can access the text of the button.

So how to get the button(QPuhButton) when a mouseReleaseEvent happens.

________________________________

From: veronique.lefrere@xxxxxx [mailto:veronique.lefrere@xxxxxx] 
Sent: Tuesday, July 10, 2007 3:44 PM
To: qt-interest@xxxxxxxxxxxxx
Subject: Re: How to get the object on which mouse is released?

 


QApplication::widgetAt ( const QPoint <http://zorro/developpement/documentation/qt4.2.2/html/qpoint.html>  & point )   [static]



QApplication::widgetAt(event->globalPos());




naveen.kmrvm@xxxxxxxxx a écrit : 

Hi All,

I have a small doubt here.

How to get the object on which mouse is released?

 

In my code I am performing a mousePressEvent on a button(say button1) and mouseReleaseEvent on another button(say button2). The problem here is I am not able to access the button on which mouseReleaseEvent is performed (ie .not able to access button2) instead it is referring to button1.

 

 

I tried with the below code but it is not working.

 

Void mouseReleaseEvent(QMouseEvent *event)

 

{

            If(event->button==4)

{

 

            QString str;

 

            str=this->text();

 

Printf("str : %s\n",str.toLatin1().data());

 

}

 

}

 

But in the above code "this pointer" is referring to the object on which the mousePressEvent happened. so how to get the object on which the mouse is released?

 

 

Regards

Naveen

 


The information contained in this electronic message and any attachments to this message are intended for the exclusive use of the addressee(s) and may contain proprietary, confidential or privileged information. If you are not the intended recipient, you should not disseminate, distribute or copy this e-mail. Please notify the sender immediately and destroy all copies of this message and any attachments. 

WARNING: Computer viruses can be transmitted via email. The recipient should check this email and any attachments for the presence of viruses. The company accepts no liability for any damage caused by any virus transmitted by this email.

www.wipro.com

 




The information contained in this electronic message and any attachments to this message are intended for the exclusive use of the addressee(s) and may contain proprietary, confidential or privileged information. If you are not the intended recipient, you should not disseminate, distribute or copy this e-mail. Please notify the sender immediately and destroy all copies of this message and any attachments. 

WARNING: Computer viruses can be transmitted via email. The recipient should check this email and any attachments for the presence of viruses. The company accepts no liability for any damage caused by any virus transmitted by this email.
 
www.wipro.com

Message 4 in thread

naveen.kmrvm@xxxxxxxxx schrieb:
>  
> 
> But *QApplication::widgetAt(event->globalPos())* function returns a 
> QWidget but I want a QPushButton so that I can access the text of the 
> button.
> 
> So how to get the button(QPuhButton) when a mouseReleaseEvent happens.

See qobject_cast.

Please don't post HTML messages, it hurts! Use plain text.

Martin

-- 
 [ signature omitted ]