Results 1 to 2 of 2

Thread: some questions about qwt scale and manipulation

  1. #1
    Join Date
    Jun 2014
    Posts
    1
    Qt products
    Qt5
    Platforms
    Unix/X11 Windows

    Default Re: some questions about qwt scale and manipulation

    now I'm developing a software to plot and manipulate some lines in the GUI, but I meet some difficulties.


    1) I hope to have a fixed scale when resize the window or the tabwidget, so that means the scale range would change but the div would not change. I read all examples of qwt, but I can't find it. it seems QwtPlotRescaler can realize it, but it seems conflict with the 2nd requirement.

    2) I have a tabwidget with more than 1 tabs for the manipulation, I hope they can use same scale, it seems I can add signal and slot connection to solve it, but when I test it, I found there is different display when I scale it by mouse wheel or resize the window. because only one tab is shown, so the hidden tab would not rescale.

    3) I hope to add manipulation of the plot. left button to manipulate the point to move and replot the line simultaneously, mid button to move, and wheel to zoom, also mouse position as the zoom center. I find some helpful information about it. QwtPlotMagnifier can help the wheel zoom, but I can't find the setting of zoom center, it always zoom by original point. QwtPlotPanner can help the move operation, what I need to do is just to change the mouse button to mid button. but I can't find any class can help for the point drag and move manipulation. In examples I found the event_filter example, it's very similar like what I need, and I tried to use similar method, but it can't work, if I set the mouse button to left button, then I can't move the point.

    A simple summary is if I want to have a lot of operations on keyboard and mouse, such as:
    a) left button single click/double click means different action
    b) left button drag from empty position is rubber band picker, from some element means drag the element
    c) midbutton drag to move the plot
    d) right button single click zoom to fit, drag means rubber band zoom
    e) left and mid button together means some operation
    f) keep left pressed, and press mid button then release left button means some operation
    ...a lot of operations, how can I realize it?

    eventFilter maybe a good solution. but if I want to use existing classes within qwt to move plot, move item, zoom...how can I call them in the eventFilter?


    Qt Code:
    1. class main_window : public QMainWindow
    2. {
    3. Q_OBJECT
    4. public:
    5. explicit main_window(QWidget *parent = 0);
    6. ~main_window();
    7. signals:
    8.  
    9. public slots:
    10.  
    11. private:
    12. QTabWidget *_tabs;
    13. };
    14.  
    15. main_window::main_window(QWidget *parent) :
    16. QMainWindow(parent)
    17. {
    18. _tabs = new QTabWidget(this);
    19. for(int n1(0);n1<2;++n1
    20. {
    21. _tabs->addTab(new QWidget(), QString::number(n1));
    22. _plots.push_back(new main_plot(_tabs->widget(n1)));
    23. QGridLayout *lay = new QGridLayout(meridional_tabs->widget(n1));
    24. lay->addWidget(main_plots[n1],0,0);
    25. main_plots[n1]->plot_curves();
    26. for(int n2(0);n2<static_cast<int>(main_plots.size());++n2)
    27. {
    28. if(n1!=n2)
    29. {
    30. connect((QObject*)(main_plots[n1]->axisWidget(QwtPlot::xBottom)),SIGNAL(scaleDivChanged()),meridional_plots[n2],SLOT(scaleDivChangedSlot()));
    31. connect((QObject*)(main_plots[n2]->axisWidget(QwtPlot::xBottom)),SIGNAL(scaleDivChanged()),meridional_plots[n1],SLOT(scaleDivChangedSlot()));
    32. }
    33. }
    34. }
    35. setCentralWidget(_tabs);
    36. }
    37.  
    38. class main_plot : public QwtPlot
    39. {
    40. Q_OBJECT
    41. public:
    42. main_plot(QWidget *parent = nullptr);
    43. public Q_SLOTS:
    44. void plot_curves();
    45. private:
    46. QVector<QwtPlotCurve*> curves;
    47. QwtPlotRescaler *rescaler;
    48. private Q_SLOTS:
    49. void scaleDivChangedSlot();
    50. };
    51.  
    52. ain_plot::main_plot(QWidget *parent ):
    53. QwtPlot( parent )
    54. {
    55. setCanvasColor( Qt::white );
    56. // Avoid jumping when label with 3 digits
    57. // appear/disappear when scrolling especially for y axis
    58. QwtScaleDraw *sdy = axisScaleDraw( QwtPlot::yLeft );
    59. sdy->setMinimumExtent( sdy->extent( axisWidget( QwtPlot::yLeft )->font() ) );
    60. setAxisTitle(QwtPlot::yLeft, "r");
    61. QwtScaleDraw *sdx = axisScaleDraw( QwtPlot::xBottom );
    62. sdx->setMinimumExtent( sdx->extent( axisWidget( QwtPlot::xBottom )->font() ) );
    63. setAxisTitle(QwtPlot::xBottom, "z");
    64. plotLayout()->setAlignCanvasToScales( true );
    65. rescaler = new QwtPlotRescaler(canvas(),QwtPlot::xBottom,QwtPlotRescaler::Expanding);
    66. rescaler->setAspectRatio(QwtPlot::yLeft,1.0);
    67. rescaler->setAspectRatio(QwtPlot::xTop,0.0);
    68. rescaler->setAspectRatio(QwtPlot::yRight,0.0);
    69. pm = new QwtPlotMagnifier( canvas() );
    70. pp = new QwtPlotPanner(canvas());
    71. pp->setMouseButton(Qt::MidButton,Qt::NoModifier);
    72. replot();
    73. }
    74.  
    75. void main_plot::plot_curves()
    76. {
    77. //add some code to plot a simple curve
    78. }
    79.  
    80. void main_plot::scaleDivChangedSlot()
    81. {
    82. QwtPlot *plt = qobject_cast<QwtPlot*>((sender())->parent());
    83. QwtInterval intv = plt->axisInterval (QwtPlot::xBottom);
    84. this->setAxisScale(QwtPlot::xBottom, intv.minValue(), intv.maxValue());
    85. intv = plt->axisInterval (QwtPlot::yLeft);
    86. this->setAxisScale(QwtPlot::yLeft, intv.minValue(), intv.maxValue());
    87. this->replot();
    88. }
    To copy to clipboard, switch view to plain text mode 

    also English is not my mother language, sometimes I can't understand the difference of scale/zoom, div/scale/interval, if anybody can explain it to me more visually, I appreciate very much.
    Last edited by silent_missile; 25th June 2014 at 09:38.

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

    Default Re: some questions about qwt scale and manipulation

    Quote Originally Posted by silent_missile View Post
    1) I hope to have a fixed scale when resize the window or the tabwidget, so that means the scale range would change but the div would not change. I read all examples of qwt, but I can't find it. it seems QwtPlotRescaler can realize it, but it seems conflict with the 2nd requirement.
    QwtPlotRescaler adjusts the scales/axes according to resize events of the plot canvas and it sounds like this is indeed what you are looking for. How to synchronize these changes with scales of another plot is another story - usually somehow done by connecting to the QwtScaleWidget::scaleDivChanged() signal.

    3) I hope to add manipulation of the plot. left button to manipulate the point to move and replot the line simultaneously, mid button to move, and wheel to zoom, also mouse position as the zoom center.
    Here you have to overload some methods of QwtPlotMagnifier.


    • QwtPlotMagnifier::widgetWheelEvent to store the position of the wheel.
    • QwtPlotMagnifier::rescale to use the position



    QwtPlotMagnifier::rescale is only a couple of lines. I would copy them to your overloaded method and modify it.

    I can't understand the difference of scale/zoom, div/scale/interval, if anybody can explain it to me more visually, I appreciate very much.
    In the terminology of qwt ( what does not necessarily has to be good English ) a scale is a scale, while zooming is usually used for for setting the range of a scale. An interval is a range with a lower and an upper bound, while a scale division is the bounding interval and the position of the ticks of a scale.

    Uwe

Similar Threads

  1. More scale questions
    By K4ELO in forum Qwt
    Replies: 3
    Last Post: 5th April 2013, 16:25
  2. HTML DOM Manipulation
    By akhilesh_s in forum Qt for Embedded and Mobile
    Replies: 0
    Last Post: 12th September 2012, 13:49
  3. Legend manipulation
    By pkj in forum Qwt
    Replies: 1
    Last Post: 17th March 2011, 07:11
  4. Text Manipulation.
    By suneel1310 in forum Qt Programming
    Replies: 7
    Last Post: 26th July 2010, 10:07
  5. Replies: 4
    Last Post: 8th May 2010, 11:40

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