Re: Custom plot selection
Quote:
I think I need to:
- Inherit from QwtPlotPicker
Yes ... I would subclass QwtPlotPicker and re-define eventFilter()
For the vertical lines, I would use QwtPlotMarker with the QwtPlotMarker::LineStyle set to VLine
Re: Custom plot selection
Use a picker with a RectRubberBand and one of the machines made for rectangles ( f.e. QwtPickerDragRectMachine ). Overload QwtPicker::drawRubberband() where you do a QPainter::drawRect() using the y coordinates from of bounding rectangle of the pickArea.
When the selection is done ( QwtPlotPicker::selected(const QRectF&) ) simply attach a QwtPlotZoneItem according to the x coordinates of the selected rectangle.
Uwe
Re: Custom plot selection
Thanks Uwe, that's essentially what I did for the drawing part, although in drawRubberband() I had created a new case for the combination of VLineRubberBand and a QwtPickerDragRectMachine. In my head, I was thinking of the selection more in the VLineRubberBand sense since I wanted the full vertical range of the plot, but your suggestion actually does seem more consistent since I really am selecting a rectangle.
I hadn't stumbled across QwtPlotZoneItem yet so I'll check that out. The name of that class just didn't trigger that it would apply.
Re: Custom plot selection
Quote:
Originally Posted by
SeanM
The name of that class just didn't trigger that it would apply.
What would be a better one ?
Uwe
Re: Custom plot selection
I don't necessarily think there's a better name for it, now that you've pointed me at it and I know it exists, I think it's aptly named for what it does. I think I was thinking in too narrow of a context so I was looking for some sort of QwtSelectionXXX class, and didn't really wonder what else it could be called.
In a more general sense, I think I was more expecting that the Qwt*Picker classes would have some sort of a keepVisible(bool) flag, which would indicate whether the selected area should remain visibly selected until the next selection sequence starts, since they're already doing the painting for creating the selection. Once I determined that wasn't the case, I just wasn't sure where to go next. And I didn't see any of the examples show either a selection where the selected area was filled with a QBrush, nor did I find an example where the selection visual was retained after the mouseReleaseEvent.
Re: Custom plot selection
Quote:
Originally Posted by
Uwe
Use a picker with a RectRubberBand and one of the machines made for rectangles ( f.e. QwtPickerDragRectMachine ). Overload QwtPicker::drawRubberband() where you do a QPainter::drawRect() using the y coordinates from of bounding rectangle of the pickArea.
Uwe
Function QwtPicker::drawRubberband() is not used anywhere in the source code, qwt library.
Re: Custom plot selection
Of course it is ( see QwtPickerRubberband::drawOverlay in qwt_picker.cpp ) - or where else do you believe gets your VLineRubberBand painted ?
Uwe
Re: Custom plot selection
Quote:
Originally Posted by
Uwe
Of course it is ( see QwtPickerRubberband::drawOverlay in qwt_picker.cpp ) - or where else do you believe gets your VLineRubberBand painted ?
Uwe
Sorry. It's my error.
class ChartZoomer : public QwtPlotZoomer
// not correct
// void drawRubberBand(QPainter *painter); // <-- it is my error!!!!
// correct
void drawRubberBand(QPainter *painter) const;
}
void drawRubberBand(QPainter *painter) const; <> void drawRubberBand(QPainter *painter);
Re: Custom plot selection
I have a similar question to the OP, so I'll put it here rather than starting a new thread, just to keep it all in context.
How does one temporarily fill the rectangular rubberband area with a translucent color? (I want the fill visible only while the rubber band is being drawn.)
My attempt was to override QwtPicker and re-implement drawRubberBand(), however this code actually does nothing. And even commenting-out the parent call at the end still results in the rectangular zoom outline being drawn. So I'm confused. Any advice Uwe would be appreciated.
SETUP
Code:
m_picker
= new XQwtPicker
( QwtPicker::RectRubberBand,
this->canvas() );
m_picker
->setRubberBandPen
( QColor( Qt
::green ) );
m_picker
->setRubberBand
( QwtPicker::CrossRubberBand );
m_picker
->setTrackerPen
( QColor( Qt
::white ) );
SUBCLASS
Code:
void XQwtPicker
::drawRubberBand( QPainter *painter
) const {
const QRect rect
= QRect( pa.
first(), pa.
last() ).
normalized();
fillColor.setAlpha(125);
// QwtPicker::drawRubberBand(painter);
}
Re: Custom plot selection
You also need to implement:
Code:
QRegion XQwtPicker
::rubberBandMask() const override;
The smaller the region the better - but beside of environments like remote X11 you probably won't notice much difference when returning the complete canvas rectangle.
In your case the optimal solution would be the rectangle spanned by the w points. See https://qwt.sourceforge.io/class_qwt...04f237062b75fc
Have a look at the implementation of QwtPicker::rubberBandMask - it will help with how to find the rectangle.
HTH,
Uwe