PDA

View Full Version : qwt mouseEvents



halberdier83
10th October 2007, 12:50
Hi all,

I have a QwtPlot in my form. And i want to put a vertical line marker when the user right mouse button clicks onto the canvas of the qwtPlot. I have no problem to set markers, but i need to get mouse click events of qwtPlot. I found the setMousePattern in QwtPlotPicker class. I used it, but nothing changed.

I wonder if QwtPlot has rightButtonClicked signal. or is there anyother way to do this?

ToddAtWSU
10th October 2007, 16:13
I haven't worked with qwt before, but do they have a mousePressEvent or mouseReleaseEvent anywhere? If you capture these events, then you can use the function, I believe it is event->button( ) or event->buttons( ) to figure out what buttons the user is pressing. If the button is right, then add your code to add your marker line. Hopefully this will help you.

halberdier83
10th October 2007, 19:48
I haven't worked with qwt before, but do they have a mousePressEvent or mouseReleaseEvent anywhere? If you capture these events, then you can use the function, I believe it is event->button( ) or event->buttons( ) to figure out what buttons the user is pressing. If the button is right, then add your code to add your marker line. Hopefully this will help you.

:) I am sorry but these classes have no signals like that. That is what i am actually asking. in qt3, i made some applications using QMouseEvent, QKeyEvent. But i realised that there is a different approach to these events in qwt. There are QwtPickerMachine, QwtEventPattern classes. But, i found no code examples so i dont know how to implement them. I also dont know whether they are what i am looking for or not. But thanks anyway for your interest.

ToddAtWSU
10th October 2007, 20:03
Aren't qwt objects objects based off different Qt objects? If so, all QWidgets have mousePressEvent and mouseReleaseEvent as far as I know. Maybe you could subclass one of these qwt classes and add in the mouse event(s) you want? Just an idea...sorry it's not a better answer.

Uwe
11th October 2007, 08:13
QwtPlot is a composite widget - for catching mouse events on its canvas you need to install an event filter for plot->canvas().
That's exactly what QwtPlotPicker does - guess this is the class, what you are looking for.

Uwe

halberdier83
11th October 2007, 08:28
QwtPlot is a composite widget - for catching mouse events on its canvas you need to install an event filter for plot->canvas().
That's exactly what QwtPlotPicker does - guess this is the class, what you are looking for.

Uwe

Hi Uwe,

I also need some sample code. QWT documentation is not enough for me. Can you provide me a sample code for this?

Uwe
11th October 2007, 19:17
I'm not sure what you want to implement, but the code below displays a vertical line, while you are pressing the right mouse button on the canvas:


QwtPlotPicker *picker = new QwtPlotPicker(plot->canvas());
picker->setSelectionFlags(QwtPicker::PointSelection | QwtPicker::DragSelection);
picker->setRubberBandPen(QColor(Qt::red));
picker->setRubberBand(QwtPicker::VLineRubberBand);
picker->setMousePattern(QwtPicker::MouseSelect1, Qt::RightButton);

If you want to add a permanent line, I would use a picker without rubberband and QwtPlotPicker::ClickSelection. Then all you need to do is to connect a slot to the QwtPlotPicker::selected signal ( you get a polygon with one point), where you attach a line marker.

HTH,
Uwe

pospiech
22nd April 2009, 13:37
I have trouble with mouseEvents as well.
I want to send the values the Tracker displays as an Signal when the plot is clicked at that point.

I tried the following



void QSpectrogramPlot::initWidget()
{
delete m_picker;
m_picker = new QwtPicker(this);
connect(m_picker, SIGNAL(selected(const QwtPolygon &)), this, SLOT(OnPickerPointSelected(const QwtPolygon &)));

// emit the position of clicks on widget
m_picker->setSelectionFlags(QwtPicker::PointSelection | QwtPicker::ClickSelection);

}

void QSpectrogramPlot::OnPickerPointSelected(const QwtPolygon & poly)
{
emit selectedPoint(poly[0]);
m_picker->reset();
}


The rest to make sure that the Polygon is empty at the next click. I do not want it to be filled with points.

However the reset is not possible to be used - does not compile.

How would I do it then?

Also QwtPolygon would be the wrong argument if I want the points of the tracker, which must be QwtPolygonF. So how do I get the points of the tracker instead ?

EDIT:

Found a solution


m_picker = new QwtPlotPicker(this->canvas());
connect(m_picker, SIGNAL(selected(const QwtDoublePoint &)), this, SLOT(OnPickerPointSelected(const QwtDoublePoint &)));

// emit the position of clicks on widget
m_picker->setSelectionFlags(QwtPicker::PointSelection | QwtPicker::ClickSelection);

}

void QSpectrogramPlot::OnPickerPointSelected(const QwtDoublePoint & p)
{
QPointF point = p;
emit selectedPoint(point);
qDebug() << QString("x: %1, y: %2").arg(point.x()).arg(point.y());
}