RE: Measurement "cursors"
Brought to you by:
rathmann
|
From: Murphy, S. <sm...@wa...> - 2019-09-18 17:27:45
|
> > Requirement 2 is the part I haven't figured out yet - how do I allow > > the user to grab a plot item to move it? I think maybe for that I want > > to look at QwtPicker? > > I would use a combination of a marker and a picker. Good, this was the path I was trying so far, so at least I was heading in the right direction. After playing around with it for a couple of days I've settled on using two pickers, both with no pen. The first picker I have set to use QwtPickerTrackerMachine as the state machine. I use this one to toggle the cursor between the standard crosshair cursor and a Qt::SplitHCursor as the user mouses near one of the measurement markers, to help indicate that they can move the cursor by clicking and dragging. The second picker uses a QwtPickerDragPointMachine and I tap into the appended, moved, and selected signals to move the relevant measurement marker. So in my case, I am actually moving the QwtPlotMarker in real-time instead of exactly following your suggestion below. Seems to be working so far, so I'm happy with that part. > Simply remove the marker from the scene, when the picker becomes active > - the rubberband ( a line in your case ) will replace it. When the picker is > done simply reinsert the marker at the new position. The next thing I need to implement, is I would like to have a small indicator next to each marker to show which marker is marker #1, and marker #2. The indicator is just a QPixmap that I generate. What I'm struggling with at the moment is that I would like the indicator to have a fixed offset from the associated marker in *pixels*. So say I want the offset to be 5 pixels. I'd like the pixmap to be 5 pixels to the right of the marker, and 5 pixels down from the top of the plot canvas, and then naturally it needs to move with the associated marker, as well as maintain that offset relationship as the plot scales are adjusted, plot is resized, etc. Would overriding void QwtPlotMarker::drawLabel (QPainter *, const QRectF &, const QPointF &) const be the best candidate for this concept? The documentation says that function is used to "align and draw the text label of the marker". I don't have a text label, but I think I could hijack that function just figure out where the indicator needs to be based on the marker's position (in pixels). Other ideas I had were: 1. Having a separate QwtPlotMarker with no pen for the indicator itself, and use the setSymbol() to get my image on there and slave the indicator marker position to the associated measurement marker's position. But that seems like it would be a lot more work since the indicator's position would be in plot data coordinates, not in raw pixels, so I think I'd have to watch for plot resize, rescale, etc. events to update the indicator's position as the marker's pixel position moves to maintain that 5 pixel offset. 2. I could move the indicator out of Qwt land, and just overlay it over the widget. But I'd still have to adjust its position during plot resize, rescale, etc. events. Not sure if there are other ways? Sean This message has been scanned for malware by Forcepoint. www.forcepoint.com |