Re: Catching mouse click in a DrawingArea



Dnia 2006-05-08 (poniedziałek) o 16:32:17 Aurélien KAMEL
<aurelien kamel gmail com> napisa_(a):

> Hello,
> 
> I would like to know how can I catch a mouse click event in a  
> DrawingArea and how can I know the coordinate of this click.
> Anybody knows if it's possible and how ?
first you need to, assign which events You need.

this->add_events(Gdk::BUTTON_PRESS_MASK);

then connect some signal:

this->signal_event().connect(sigc::mem_fun(*this,
&YourArea::on_event_happend) );

and you can read mouse coordinates here like this:
 
bool MyArea::on_event_happend(GdkEvent *event) {
	if (event->type == GDK_BUTTON_PRESS) {
		std::cout << "clicked: X= " << event->button.x
			<< " Y= " << event->button.y
			<< std::endl;
	}
	return false;
}



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]