Results 1 to 11 of 11

Thread: Custom plot selection

  1. #1
    Join Date
    Jan 2014
    Posts
    36
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows

    Default Custom plot selection

    I'm trying to create a custom plot area selection effect and just want to make sure I'm thinking of it the right way. I've attached a couple screenshots/mockups to illustrate what I'm going for.

    What I need: Our plots have time on the X axis and multiple curves. The user needs to be able to select a subset of data bounded by start and end times, but there's no need to be able to select based on Y values. So the selection should contain the entire Y content of the plot, between the two X points the user selected. After the user releases the mouse button to end the selection, the selected area should remain visible, ideally it would have solid vertical lines marking the start/end points (QPen with alpha of 255), and then have a semi-transparent filled in area (QBrush with alpha of 50% or so). The desired effect is shown in this mocked up image:
    desiredSelection.png
    So in this mockup, the user clicked at X=95.7333, dragged until 221.1770 and released.

    My attempts so far:
    startSelection.png
    In this first image, I've got a QwtPlotPicker with a VLineRubberBand and a QwtPickerDragPointMachine. This gives a nice vertical cursor showing where the selection is starting from, but as the user performs a click/drag/release sequence there's a couple issues: the cursor moves from the starting point to the ending point, so when you reach the end, there's no visual cue to where the selection started, and the signal that is emitted is QwtPlotPicker::selected(const QPointF &pos), which only contains the ending (X,Y) values.

    Second attempt:
    rectSelection.png
    In this image, I'm now using a RectRubberBand and a QwtPickerDragRectMachine. This gives the visual of both the starting and ending selection positions (at least up until mouse release), and emits QwtPlotPicker::selected(const QRectF&), which gives me both the starting X and width, so that's good. But visually it doesn't span the entire plot Y range, and doesn't stay visible after the mouse is released.

    So it seems like I want the VLineRubberBand visual combined with a QwtPickerDragRectMachine (but those don't seem compatible? http://qwt.sourceforge.net/class_qwt...78d2823c1f7894). I need to add a fill effect, and then I need some way to get the selection to remain visible until the next selection starts?

    I think I need to:
    - Inherit from QwtPlotPicker
    - Figure out how to get a VLineRubberBand effect combined with emitting a QRectF signal so that I get both start/end or start/width, probably by overloading virtual void drawRubberBand (QPainter *) const?
    - Add a fill effect during the selection, I think using QBrush? Looks like this helps? http://www.qtcentre.org/threads/4890...ubberband+fill
    - And then get the visual to persist. QwtWidgetOverlay?

  2. #2
    Join Date
    Dec 2013
    Location
    Toronto, Canada
    Posts
    62
    Thanked 16 Times in 15 Posts
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: Custom plot selection

    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

  3. #3
    Join Date
    Feb 2006
    Location
    Munich, Germany
    Posts
    3,309
    Thanked 879 Times in 827 Posts
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows

    Default 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

  4. #4
    Join Date
    Jan 2014
    Posts
    36
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows

    Default 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.

  5. #5
    Join Date
    Feb 2006
    Location
    Munich, Germany
    Posts
    3,309
    Thanked 879 Times in 827 Posts
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Custom plot selection

    Quote Originally Posted by SeanM View Post
    The name of that class just didn't trigger that it would apply.
    What would be a better one ?

    Uwe

  6. #6
    Join Date
    Jan 2014
    Posts
    36
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows

    Default 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.

  7. #7
    Join Date
    Apr 2011
    Posts
    7
    Thanks
    2
    Thanked 1 Time in 1 Post
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows Android

    Default Re: Custom plot selection

    Quote Originally Posted by Uwe View Post
    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.

  8. #8
    Join Date
    Feb 2006
    Location
    Munich, Germany
    Posts
    3,309
    Thanked 879 Times in 827 Posts
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows

    Default 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

  9. #9
    Join Date
    Apr 2011
    Posts
    7
    Thanks
    2
    Thanked 1 Time in 1 Post
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows Android

    Default Re: Custom plot selection

    Quote Originally Posted by Uwe View Post
    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);
    Last edited by gorec323; 1st March 2014 at 14:19.

  10. #10
    Join Date
    Dec 2011
    Posts
    60
    Thanks
    12
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default 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
    Qt Code:
    1. m_picker = new XQwtPicker( QwtPicker::RectRubberBand,
    2. QwtPicker::AlwaysOn,
    3. this->canvas() );
    4. m_picker->setRubberBandPen( QColor( Qt::green ) );
    5. m_picker->setRubberBand( QwtPicker::CrossRubberBand );
    6. m_picker->setTrackerPen( QColor( Qt::white ) );
    To copy to clipboard, switch view to plain text mode 

    SUBCLASS
    Qt Code:
    1. void XQwtPicker::drawRubberBand( QPainter *painter ) const
    2. {
    3. const QPolygon pa = QwtPicker::selection();
    4. const QRect rect = QRect( pa.first(), pa.last() ).normalized();
    5.  
    6. QColor fillColor = QwtPicker::rubberBandPen().color();
    7. fillColor.setAlpha(125);
    8.  
    9. QBrush fillBrush(fillColor);
    10.  
    11. QwtPainter::fillRect( painter, rect, fillBrush );
    12.  
    13. // QwtPicker::drawRubberBand(painter);
    14. }
    To copy to clipboard, switch view to plain text mode 

  11. #11
    Join Date
    Feb 2006
    Location
    Munich, Germany
    Posts
    3,309
    Thanked 879 Times in 827 Posts
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Custom plot selection

    You also need to implement:

    Qt Code:
    1. QRegion XQwtPicker::rubberBandMask() const override;
    To copy to clipboard, switch view to plain text mode 
    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

  12. The following user says thank you to Uwe for this useful post:

    alketi (11th May 2020)

Similar Threads

  1. Replies: 1
    Last Post: 24th May 2012, 12:52
  2. [Qwt] selection of curve/plot/...
    By packman2012 in forum Qt-based Software
    Replies: 0
    Last Post: 5th April 2012, 10:39
  3. Replies: 2
    Last Post: 19th April 2010, 13:49
  4. Replies: 5
    Last Post: 10th February 2010, 12:08
  5. Custom items selection in qgraphicsscene
    By yonnak in forum Qt Programming
    Replies: 7
    Last Post: 28th March 2009, 12:32

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.