Results 1 to 10 of 10

Thread: How to situate the second QwtPlot under the first QwtPlot smoothly???

  1. #1
    Join Date
    Jul 2012
    Posts
    11
    Qt products
    Qt4
    Platforms
    Windows

    Default How to situate the second QwtPlot under the first QwtPlot smoothly???

    Hi)I have two QwtyPlots A and B. I set A and B into the QGridLayout. QwtPlot B is under the QwtPlot A. The yAxi's of QwtPlot A belongs to (1000000;90000000) and yAxis of QwtPlot B to (1;10), that's why the left edges of qwtplots are not smoothly((((How can I do it???Please, help!I saw the example plotmatrix and didn't find there the decision!!!

  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: How to situate the second QwtPlot under the first QwtPlot smoothly???

    Quote Originally Posted by dqrest View Post
    I saw the example plotmatrix and didn't find there the decision!!!
    The basic idea is to assign a fixed extent for all y axes calculated from the maximum needed extent.

    You find the code in this example.
    Uwe

  3. #3
    Join Date
    Jul 2012
    Posts
    11
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: How to situate the second QwtPlot under the first QwtPlot smoothly???

    How can I assign a fixed extent for all y axes???Please, give me an example))

  4. #4
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: How to situate the second QwtPlot under the first QwtPlot smoothly???

    Iterate over scale draw's of y axis of all plots, get their extents, calculate the maximum and then iterate over all plots again setting that maximum as a minimum extent. You can see how to do it in the plotmatrix Qwt example.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  5. #5
    Join Date
    Sep 2007
    Posts
    61
    Thanks
    5
    Thanked 4 Times in 4 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: How to situate the second QwtPlot under the first QwtPlot smoothly???

    Unfortunately, this approach doesn't work when you have labels on the axis. I'm not exactly sure why. We need a new layout algorithm which understands how to really lay plots beside or next to one another.

    Consider the following diff:
    Qt Code:
    1. Index: plotmatrix/plotmatrix.cpp
    2. ===================================================================
    3. --- plotmatrix/plotmatrix.cpp (revision 1474)
    4. +++ plotmatrix/plotmatrix.cpp (working copy)
    5. @@ -47,6 +47,9 @@
    6. QwtPlot *plot = new QwtPlot( this );
    7. layout->addWidget( plot, row, col );
    8.  
    9. +if (row == 0 && col == 0) plot->axisWidget (QwtPlot::yLeft)->setTitle ("Line 1");
    10. +if (row == 1 && col == 0) plot->axisWidget (QwtPlot::yLeft)->setTitle ("Line 1<BR>Units");
    11. +
    12. for ( int axis = 0; axis < QwtPlot::axisCnt; axis++ )
    13. {
    14. connect( plot->axisWidget( axis ),
    To copy to clipboard, switch view to plain text mode 

    Are there other ideas? I find I can get it close sometimes, but I never quite it completely right regardless of what I try when I have varying labels on the axes, and varying limits on the axes.

    Cheers,
    Joey

  6. #6
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: How to situate the second QwtPlot under the first QwtPlot smoothly???

    This works:

    diff Code:
    1. ===================================================================
    2. --- plotmatrix.cpp (revision 1452)
    3. +++ plotmatrix.cpp (working copy)
    4. @@ -47,6 +47,9 @@
    5. QwtPlot *plot = new QwtPlot( this );
    6. layout->addWidget( plot, row, col );
    7.  
    8. + if (row == 0 && col == 0) plot->axisWidget (QwtPlot::yLeft)->setTitle ("Line 1");
    9. + if (row == 1 && col == 0) plot->axisWidget (QwtPlot::yLeft)->setTitle ("Line 1<BR>Units");
    10. +
    11. for ( int axis = 0; axis < QwtPlot::axisCnt; axis++ )
    12. {
    13. connect( plot->axisWidget( axis ),
    14. @@ -276,7 +279,9 @@
    15. QwtScaleDraw *sd = scaleWidget->scaleDraw();
    16. sd->setMinimumExtent( 0.0 );
    17.  
    18. - const double extent = sd->extent( scaleWidget->font() );
    19. + double extent = sd->extent( scaleWidget->font() );
    20. + if( !scaleWidget->title().isEmpty())
    21. + extent += scaleWidget->title().textSize().height();
    22. if ( extent > maxExtent )
    23. maxExtent = extent;
    24. }
    25. @@ -287,7 +292,11 @@
    26. if ( p )
    27. {
    28. QwtScaleWidget *scaleWidget = p->axisWidget( axis );
    29. - scaleWidget->scaleDraw()->setMinimumExtent( maxExtent );
    30. + double extent = maxExtent;
    31. + if(!scaleWidget->title().text().isEmpty()) {
    32. + extent -= scaleWidget->title().textSize().height();
    33. + }
    34. + scaleWidget->scaleDraw()->setMinimumExtent( extent );
    35. }
    36. }
    37. }
    To copy to clipboard, switch view to plain text mode 

    Of course in a general case you have to take into account the font of the title, which I ignored assuming it is the default one. You should also consider the spacing between the title and the scale (you can see there is an "off by 1" (or 2) error in the result of my patch).
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  7. #7
    Join Date
    Sep 2007
    Posts
    61
    Thanks
    5
    Thanked 4 Times in 4 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: How to situate the second QwtPlot under the first QwtPlot smoothly???

    Thanks for that! I wasn't using textSize so I was getting different answers. One more thing is if there is a legend on only one side, there will be a misalignment, even using the logic of adding/subtracting. Is there a way to correct for that?

    Here's a diff:

    Qt Code:
    1. Index: plotmatrix/plotmatrix.cpp
    2. ===================================================================
    3. --- plotmatrix/plotmatrix.cpp (revision 1477)
    4. +++ plotmatrix/plotmatrix.cpp (working copy)
    5. @@ -14,6 +14,9 @@
    6. #include <qwt_plot.h>
    7. #include <qwt_scale_widget.h>
    8. #include <qwt_scale_draw.h>
    9. +#include <qwt_plot_curve.h>
    10. +#include <qwt_plot_layout.h>
    11. +#include <qwt_legend.h>
    12. #include "plotmatrix.h"
    13.  
    14. class PlotMatrix::PrivateData
    15. @@ -47,6 +50,30 @@
    16. QwtPlot *plot = new QwtPlot( this );
    17. layout->addWidget( plot, row, col );
    18.  
    19. +if (row == 0 && col == 0) plot->axisWidget (QwtPlot::yLeft)->setTitle ("Hello!");
    20. +if (row == 1 && col == 0) plot->axisWidget (QwtPlot::yLeft)->setTitle ("Hello!<BR>Units");
    21. +if (row == 1 && col == 3) {
    22. + QVector <QPointF> data;
    23. + data.push_back (QPointF (-420, 10));
    24. + data.push_back (QPointF (940, -10));
    25. + QwtPlotCurve *curve = new QwtPlotCurve ("data");
    26. + curve->setSamples (data);
    27. + curve->setPen( QPen( Qt::cyan ) );
    28. + curve->attach (plot);
    29. + // legend
    30. + QwtLegend *legend = new QwtLegend;
    31. + plot->insertLegend( legend, QwtPlot::RightLegend );
    32. +}
    33. +
    34. for ( int axis = 0; axis < QwtPlot::axisCnt; axis++ )
    35. {
    36. connect( plot->axisWidget( axis ),
    37. @@ -276,7 +303,13 @@
    38. QwtScaleDraw *sd = scaleWidget->scaleDraw();
    39. sd->setMinimumExtent( 0.0 );
    40.  
    41. - const double extent = sd->extent( scaleWidget->font() );
    42. + double extent = sd->extent( scaleWidget->font() );
    43. + if( !scaleWidget->title().isEmpty())
    44. + extent += scaleWidget->title().textSize().height();
    45. + if (p->legend () && axis == p->plotLayout ()->legendPosition ()) {
    46. + double legendSize = p->legend ()->sizeHint ().width ();
    47. + extent += legendSize;
    48. + }
    49. if ( extent > maxExtent )
    50. maxExtent = extent;
    51. }
    52. @@ -287,7 +320,16 @@
    53. if ( p )
    54. {
    55. QwtScaleWidget *scaleWidget = p->axisWidget( axis );
    56. - scaleWidget->scaleDraw()->setMinimumExtent( maxExtent );
    57. + double extent = maxExtent;
    58. + if(!scaleWidget->title().text().isEmpty()) {
    59. + extent -= scaleWidget->title().textSize().height();
    60. + }
    61. +
    62. + if (p->legend () && axis == p->plotLayout ()->legendPosition ()) {
    63. + double legendSize = p->legend ()->sizeHint ().width ();
    64. + extent -= legendSize;
    65. + }
    66. + scaleWidget->scaleDraw()->setMinimumExtent( extent );
    67. }
    68. }
    69. }
    To copy to clipboard, switch view to plain text mode 

  8. #8
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: How to situate the second QwtPlot under the first QwtPlot smoothly???

    You have to compensate for whatever decoration/primitive you want to be dynamic the same way I compensated for the axis title. If you have a legend, take it into consideration when calculating the extent.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  9. #9
    Join Date
    Sep 2007
    Posts
    61
    Thanks
    5
    Thanked 4 Times in 4 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: How to situate the second QwtPlot under the first QwtPlot smoothly???

    Yes! I did that (even in the above diff); however, it is still off by 1 or 2. For some reason, the legend size that I get from p->legend ()->sizeHint () is not quite right. There is a margin or spacing of some sort, but trying to compensate for that similarly does seem to work. I keep thinking sizeHint isn't the right way to go about this, but I don't see other alternatives.

  10. #10
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: How to situate the second QwtPlot under the first QwtPlot smoothly???

    sizeHint() is probably ok but there is certainly some spacing involved. Look into Qwt source code to see how to calculate everything.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


Similar Threads

  1. QwtPlot stretching
    By jmsbc in forum Qwt
    Replies: 7
    Last Post: 27th August 2013, 08:43
  2. QwtPlot filter
    By simonb in forum Qwt
    Replies: 2
    Last Post: 10th July 2012, 17:15
  3. how to scroll qwtplot?
    By alizadeh91 in forum Qwt
    Replies: 15
    Last Post: 9th July 2012, 11:52
  4. How to keep rubberband on the QwtPlot?
    By xujiqiang0927 in forum Qwt
    Replies: 2
    Last Post: 3rd June 2010, 03:46
  5. Replies: 6
    Last Post: 14th May 2009, 13:02

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.