PDA

View Full Version : Move the Legend widget using MouseEvent



umulingu
5th June 2010, 07:42
Hai

How to move the Legend widget using MouseMove Event ?

suggestion please





suree

Bangalore

high_flyer
7th June 2010, 08:55
Override the mouseMoveEvent(), extract mouse position from event object, and use it to set widgets position.

amoswood
8th June 2010, 15:58
Override the mouseMoveEvent(), extract mouse position from event object, and use it to set widgets position.

Make sure to insert your legend class using QwtPlot::insertLegend(your_legend_p, QwtPlot::ExternalLegend) though. This will make the legend a child of the plot instead of placing it somewhere else. Then you can simply captue the mouseMoveEvent() events and then just set your geometry however you would like on your legend widget.:)

umulingu
16th June 2010, 11:01
Thanks for ur reply
Hai
In my Project, I have a Main Widget in that QWT Plot Widget and some other widgets [QList ..].
I can get the MouseMoveEvent of my MainWidget but not able to get QWTPlot MouseMoveEvent.

suggestion please



void MainPlot::mousePressEvent(QMouseEvent *event) // this is my MainWidget called MainPlot
{
------
------
}


and
my QWTPLOT Mouse Event is


void MainPlot::ui->uPlot->mouseMoveEvent(QMouseEvent *) // Uplot is my QWTPLOT widget
{
// some code
------------------
-------------------

}


suree
India

amoswood
16th June 2010, 14:33
One thing to watch out for is that the plot canvas is a separate widget from the plot itself. The canvas is a child of the plot. More than like you need to watch from the mouse move event in uPlot->canvas().

Additionally, you have to turn on the mouse tracking for a widget in order to get mouseMoveEvents. You should use:


uPlot->setMouseTracking(true);
uPlot->canvas()->setMouseTracking(true);