Results 1 to 2 of 2

Thread: Multiple, always visible QwtPickers

  1. #1
    Join Date
    Jan 2013
    Posts
    12
    Thanks
    2

    Default Multiple, always visible QwtPickers

    I need to put a number of always-visible pickers on a canvas. This is the code I have devised so far:
    Qt Code:
    1. class QwtPickerStayMachine : public QwtPickerMachine
    2. {
    3. public:
    4. QwtPickerStayMachine():
    5. QwtPickerMachine( PointSelection )
    6. {
    7. // 0 = button not pressed
    8. // 1 = button pressed
    9. setState(0);
    10. }
    11.  
    12. QList<QwtPickerMachine::Command> transition(
    13. const QwtEventPattern &eventPattern, const QEvent *e )
    14. {
    15. QList<QwtPickerMachine::Command> cmdList;
    16.  
    17. switch ( e->type() )
    18. {
    19. case QEvent::MouseButtonPress:
    20. {
    21. if ( eventPattern.mouseMatch(
    22. QwtEventPattern::MouseSelect1, ( const QMouseEvent * )e ) )
    23. {
    24. if ( state() == 0 )
    25. {
    26. cmdList += End;
    27. cmdList += Begin;
    28. cmdList += Append;
    29. setState(1);
    30. }
    31. else
    32. {
    33. //cmdList += Move;
    34. }
    35. //qDebug() << "machine mousebuttonpress state" << state() ;
    36. }
    37. break;
    38. }
    39. case QEvent::MouseMove:
    40. case QEvent::Wheel:
    41. {
    42. if ( state() == 0 )
    43. {
    44.  
    45. }
    46. else
    47. {
    48. cmdList += Move;
    49. }
    50. //qDebug() << "machine mousemove state" << state();
    51. break;
    52. }
    53. case QEvent::MouseButtonRelease:
    54. {
    55. //setState(0);
    56. if ( state() == 0 )
    57. {
    58.  
    59. }
    60. else
    61. {
    62. //cmdList += End;
    63. setState(0);
    64. }
    65. //qDebug() << "machine mousebuttonrelease state" << state();
    66. break;
    67. }
    68. case QEvent::Leave:
    69. {
    70. //setState(0);
    71. //qDebug() << "machine leave state" << state();
    72. }
    73. case QEvent::KeyPress:
    74. {
    75. if ( eventPattern.keyMatch(
    76. QwtEventPattern::KeySelect1, ( const QKeyEvent * )e ) )
    77. {
    78. if ( state() == 0 )
    79. {
    80. cmdList += Begin;
    81. cmdList += Append;
    82. setState( 1 );
    83. }
    84. else
    85. {
    86. //cmdList += End;
    87. //setState( 0 );
    88. }
    89. }
    90. break;
    91. }
    92. default:
    93. break;
    94. }
    95.  
    96. return cmdList;
    97. }
    98. };
    To copy to clipboard, switch view to plain text mode 
    It seems to work and the rubberband stays visible. I instantiate the picker in its constructor like in the following code
    Qt Code:
    1. Picker(QwtPlotCanvas *canvas, QColor col)
    2. : QwtPicker(canvas)
    3. {
    4. //setStateMachine( new QwtPickerDragPointMachine() );
    5. setStateMachine( new QwtPickerStayMachine() );
    6. setRubberBandPen(QPen(QBrush(col), 3));
    7. //setRubberBand( QwtPicker::NoRubberBand );
    8. setRubberBand( QwtPicker::VLineRubberBand );
    9. setTrackerMode(QwtPicker::AlwaysOn);
    10. setTrackerPen( QColor( Qt::blue ) );
    11.  
    12. connect(this, SIGNAL(moved(QPoint)), this, SLOT(onPickerDragged(QPoint)));
    13. }
    To copy to clipboard, switch view to plain text mode 
    The first type of problem I am facing is that the signal moved() does not seem to be emitted, as the code on the connected slot is never called.
    The second problem is that when I associate two pickers to the canvas, they move synchronously one over another, when actually I would like to move just one of them (the one nearest to the point where I click).
    Thanks for any advice.

  2. #2
    Join Date
    Feb 2006
    Location
    Munich, Germany
    Posts
    3,326
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows
    Thanked 880 Times in 828 Posts

    Default Re: Multiple, always visible QwtPickers

    Use markers ( QwtPlotMarker::VLine ) and one picker only !

    Connect a slot to the selected() signal of the picker, where you identify the corresponding marker ( closest line ), hide it and let the rubber band ( same pen as the marker ) of the picker take its place. When the picker selection is done, move the marker to the new position and make it visible again.

    Have look at the itemeditor example of Qwt 6.1. Your situation is easier as the rubber band of a picker already has the option to look exactly like a line marker, but it might be interesting to get the idea:

    1) select an item
    2) hide the item, let the widget overlay ( the rubberband of a picker is one ) take its place
    3) move the item to its new position and show it again

    This is the way I am implementing drag and drop of plot items myself.

    Uwe

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

    gibi70 (8th February 2013)

Similar Threads

  1. QPainter::end() slow when multiple QGLWidgets visible
    By cbamber85 in forum Qt Programming
    Replies: 0
    Last Post: 4th November 2012, 12:38
  2. using one signal to update multiple multiple controls
    By henryjoye in forum Qt Programming
    Replies: 7
    Last Post: 13th December 2011, 15:19
  3. Replies: 2
    Last Post: 19th October 2011, 10:30
  4. Replies: 1
    Last Post: 17th May 2011, 17:12
  5. Replies: 0
    Last Post: 21st December 2006, 12:48

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
  •  
Qt is a trademark of The Qt Company.