Results 1 to 5 of 5

Thread: Crosshairs that are always on

  1. #1
    Join Date
    Nov 2006
    Location
    Netherlands
    Posts
    6
    Thanks
    1
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

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

  2. #2
    Join Date
    May 2008
    Location
    Melbourne, Australia
    Posts
    136
    Thanks
    9
    Thanked 3 Times in 3 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Crosshairs that are always on

    I'm not familiar with that Qwt function, but you could use this to get a crosshairs:
    Qt Code:
    1. QApplication::setOverrideCursor(Qt::CrossCursor);
    To copy to clipboard, switch view to plain text mode 
    http://doc.trolltech.com/4.4/qt.html#CursorShape-enum

  3. #3
    Join Date
    Nov 2006
    Location
    Netherlands
    Posts
    6
    Thanks
    1
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

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

  4. #4
    Join Date
    Feb 2006
    Location
    Munich, Germany
    Posts
    3,241
    Thanked 860 Times in 809 Posts
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Crosshairs that are always on

    Qt Code:
    1. class PickerMachine: public QwtPickerMachine
    2. {
    3. public:
    4. virtual QwtPickerMachine::CommandList transition(
    5. const QwtEventPattern &, const QEvent *e)
    6. {
    7. QwtPickerMachine::CommandList cmdList;
    8. if ( e->type() == QEvent::MouseMove )
    9. cmdList += Move;
    10.  
    11. return cmdList;
    12. }
    13. };
    14.  
    15. class Picker: public QwtPlotPicker
    16. {
    17. public:
    18. Picker(QwtPlotCanvas *canvas):
    19. QwtPlotPicker(QwtPlot::xBottom, QwtPlot::yLeft, canvas)
    20. {
    21. setRubberBand(QwtPlotPicker::CrossRubberBand);
    22. setRubberBandPen(QColor(Qt::green));
    23. setRubberBand(QwtPicker::CrossRubberBand);
    24.  
    25. canvas->setMouseTracking(true);
    26. }
    27.  
    28. void widgetMouseMoveEvent(QMouseEvent *e)
    29. {
    30. if ( !isActive() )
    31. {
    32. setSelectionFlags(QwtPicker::PointSelection);
    33.  
    34. begin();
    35. append(e->pos());
    36. }
    37.  
    38. QwtPlotPicker::widgetMouseMoveEvent(e);
    39. }
    40.  
    41. void widgetLeaveEvent(QEvent *)
    42. {
    43. end();
    44. }
    45.  
    46. virtual QwtPickerMachine *stateMachine(int) const
    47. {
    48. return new PickerMachine;
    49. }
    50. };
    To copy to clipboard, switch view to plain text mode 

    HTH,
    Uwe

  5. The following 3 users say thank you to Uwe for this useful post:

    AlekseyK (9th March 2016), Lupus (21st July 2010), xburgerhout (10th February 2009)

  6. #5
    Join Date
    Nov 2006
    Location
    Netherlands
    Posts
    6
    Thanks
    1
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Thumbs up Re: Crosshairs that are always on

    Thanks Uwe,

    That's exactly what I was looking for.

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.