Crosshairs that are always on
Hi all,
I'm trying to create some crosshairs that follow the mouse. The effect I'm trying to achieve is that of QwtPicker(PointSelection, CrossRubberBand, AlwaysOn), but without having to click the mouse to activate the rubberband.
Of course, I can probably achieve this by using two plot markers that follow the mouse position (or drawing the lines directly in a paintEvent()), but I was wondering if there is an easier solution / better way to do it.
Re: Crosshairs that are always on
I'm not familiar with that Qwt function, but you could use this to get a crosshairs:
http://doc.trolltech.com/4.4/qt.html#CursorShape-enum
Re: Crosshairs that are always on
That's not the effect I had in mind, but thanks for the reply anyway.
What I want is for the cross to span the entire plot canvas. This is what you get when you create a picker with PointSelection and a CrossRubberband. Clicking the mouse shows the cross rubberband on the plot at the current mouse location. However, you will need to click the mouse, and I want the CrossRubberband to be shown always.
As far as I can tell from the qwt-5.2 (svn) sources, qwt only draws the CrossRubberband in 'PointSelection' mode.
Using a plot marker has the disadvantage that moving the mouse results in a repaint off the entire plot, so this is a solution that will only work if the plot is simple.
Alternatively, it is possible to implement an overlay widget that paints the cross (this is exactly what qwt does for the CrossRubberband, that's why I was hoping I could use a plot picker).
Re: Crosshairs that are always on
Code:
{
public:
{
if ( e
->type
() == QEvent::MouseMove ) cmdList += Move;
return cmdList;
}
};
{
public:
{
setRubberBandPen
(QColor(Qt
::green));
canvas->setMouseTracking(true);
}
{
if ( !isActive() )
{
setSelectionFlags
(QwtPicker::PointSelection);
begin();
append(e->pos());
}
}
void widgetLeaveEvent
(QEvent *) {
end();
}
{
return new PickerMachine;
}
};
HTH,
Uwe
Re: Crosshairs that are always on
Thanks Uwe,
That's exactly what I was looking for.