Results 1 to 4 of 4

Thread: QwtPlotPicker stay visible after DoubleMouseClick

  1. #1
    Join Date
    Mar 2018
    Posts
    2
    Qt products
    Qt5
    Platforms
    Windows

    Default QwtPlotPicker stay visible after DoubleMouseClick

    Hello,

    i use in my QwtPlot a curve tracker like in the playground example "CurveTracker".

    Qt Code:
    1. #include "curvetracker.h"
    2. #include <qwt_picker_machine.h>
    3. #include <qwt_series_data.h>
    4. #include <qwt_plot.h>
    5. #include <qwt_plot_curve.h>
    6.  
    7. struct compareX
    8. {
    9. inline bool operator()( const double x, const QPointF &pos ) const
    10. {
    11. return ( x < pos.x() );
    12. }
    13. };
    14.  
    15. CurveTracker::CurveTracker( QWidget *canvas ):
    16. QwtPlotPicker( canvas )
    17. {
    18. setTrackerMode( QwtPlotPicker::ActiveOnly );
    19. setRubberBand( VLineRubberBand );
    20.  
    21. setStateMachine( new QwtPickerDragPointMachine() );
    22. }
    23.  
    24. QRect CurveTracker::trackerRect( const QFont &font ) const
    25. {
    26. QRect r = QwtPlotPicker::trackerRect( font );
    27.  
    28. // align r to the first curve
    29.  
    30. const QwtPlotItemList curves = plot()->itemList( QwtPlotItem::Rtti_PlotCurve );
    31. if ( curves.size() > 0 )
    32. {
    33. QPointF pos = invTransform( trackerPosition() );
    34.  
    35. const QLineF line = curveLineAt(
    36. static_cast<const QwtPlotCurve *>( curves[0] ), pos.x() );
    37. if ( !line.isNull() )
    38. {
    39. const double curveY = line.pointAt(
    40. ( pos.x() - line.p1().x() ) / line.dx() ).y();
    41.  
    42. pos.setY( curveY );
    43. pos = transform( pos );
    44.  
    45. r.moveBottom( pos.y() );
    46. }
    47. }
    48.  
    49. return r;
    50. }
    51.  
    52. QwtText CurveTracker::trackerTextF( const QPointF &pos ) const
    53. {
    54. QwtText trackerText;
    55.  
    56. trackerText.setColor( Qt::black );
    57.  
    58. QColor c( "#333333" );
    59. trackerText.setBorderPen( QPen( c, 2 ) );
    60. c.setAlpha( 200 );
    61. trackerText.setBackgroundBrush( c );
    62.  
    63. QString info;
    64.  
    65. const QwtPlotItemList curves =
    66. plot()->itemList( QwtPlotItem::Rtti_PlotCurve );
    67.  
    68. for ( int i = 0; i < curves.size(); i++ )
    69. {
    70. const QString curveInfo = curveInfoAt(
    71. static_cast<const QwtPlotCurve *>( curves[i] ), pos );
    72.  
    73. if ( !curveInfo.isEmpty() )
    74. {
    75. if ( !info.isEmpty() )
    76. info += "<br>";
    77.  
    78. info += curveInfo;
    79. }
    80. }
    81.  
    82. trackerText.setText( info );
    83. return trackerText;
    84. }
    85.  
    86. QString CurveTracker::curveInfoAt(
    87. const QwtPlotCurve *curve, const QPointF &pos ) const
    88. {
    89. const QLineF line = curveLineAt( curve, pos.x() );
    90. if ( line.isNull() )
    91. return QString::null;
    92.  
    93. const double y = line.pointAt(
    94. ( pos.x() - line.p1().x() ) / line.dx() ).y();
    95.  
    96. QString info( "<font color=""%1"">%2</font>" );
    97. return info.arg( curve->pen().color().name() ).arg( y );
    98. }
    99.  
    100. QLineF CurveTracker::curveLineAt(
    101. const QwtPlotCurve *curve, double x ) const
    102. {
    103. QLineF line;
    104.  
    105. if ( curve->dataSize() >= 2 )
    106. {
    107. const QRectF br = curve->boundingRect();
    108. if ( ( br.width() > 0 ) && ( x >= br.left() ) && ( x <= br.right() ) )
    109. {
    110. int index = qwtUpperSampleIndex<QPointF>(
    111. *curve->data(), x, compareX() );
    112.  
    113. if ( index == -1 &&
    114. x == curve->sample( curve->dataSize() - 1 ).x() )
    115. {
    116. // the last sample is excluded from qwtUpperSampleIndex
    117. index = curve->dataSize() - 1;
    118. }
    119.  
    120. if ( index > 0 )
    121. {
    122. line.setP1( curve->sample( index - 1 ) );
    123. line.setP2( curve->sample( index ) );
    124. }
    125. }
    126. }
    127.  
    128. return line;
    129. }
    To copy to clipboard, switch view to plain text mode 
    This works and i get always the values from the actual Mouse Position.

    Now i want to double Click at a selected position and want the tracker to stay visible also when i move the mouse outside the plot area.

    How can i manage this?

    Thanks for help

    DSP

  2. #2
    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: QwtPlotPicker stay visible after DoubleMouseClick

    This first step is to terminate the picker on double clicks, what can be done by overloading the transition() method of your QwtPickerMachine. Have a look at the code in qwt_picker_machine.cpp and you will know what to do.
    Then I would connect a slot to the QwtPlotPicker::selected signal, where you simply insert a QwtPlotMarker at the selected position, that looks like the cursor of the picker.

    Uwe

  3. #3
    Join Date
    Mar 2018
    Posts
    2
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: QwtPlotPicker stay visible after DoubleMouseClick

    Hi Uwe,

    sorry i didn't get it.

    My CurveTracker class is derived from QwtPlotPicker.
    Where should i overload the transition function from QwtPickerMachine class?

    Do i have to write a own MyPickerMachine class and handle all the stuff there?
    Then i could overload the transistion function and could try to catch the double click event.
    Who does emit the selected signal?

    Thanks for further explanations

  4. #4
    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: QwtPlotPicker stay visible after DoubleMouseClick

    Quote Originally Posted by DSP View Post
    My CurveTracker class is derived from QwtPlotPicker.
    Where should i overload the transition function from QwtPickerMachine class?
    Inherit from whatever machine your picker is using ( in the curvetracker example it is a QwtPickerDragPointMachine ), extend/configure it by overloading its virtual methods ad then add it with:

    Qt Code:
    1. yourPicker->setStateMachine( yourStateMachine )
    To copy to clipboard, switch view to plain text mode 
    Of course you can also write your own state machine from scratch if you prefer that.

    Who does emit the selected signal?
    Well a picker is for selecting points/rects/polygons ( in your case a point ) and the selected signal emits the result of the selection, what should contain the position, where to insert the marker.

    Uwe

Similar Threads

  1. Replies: 3
    Last Post: 2nd January 2018, 14:04
  2. tooltip doesn't stay
    By mqt in forum Qt Programming
    Replies: 0
    Last Post: 16th July 2013, 15:51
  3. QMenu to stay open
    By xmeister in forum Qt Programming
    Replies: 4
    Last Post: 20th July 2012, 03:17
  4. How to make a window stay on top of all others?
    By Momergil in forum Qt Programming
    Replies: 9
    Last Post: 16th July 2012, 21:25
  5. QScrollArea stay down
    By bunjee in forum Qt Programming
    Replies: 2
    Last Post: 3rd June 2008, 12:14

Tags for this Thread

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.