Results 1 to 4 of 4

Thread: qwt6.0.1 legend problem

  1. #1
    Join Date
    Nov 2007
    Posts
    55
    Thanks
    1
    Thanked 9 Times in 9 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default qwt6.0.1 legend problem

    Hello to everyone,
    I have written a piece of code to show the result of a frequency spectrum computation.
    The curve is well plotted, but I am missing the legend. I tried out several variants, but nothing helped.
    See the code below:

    Qt Code:
    1. // plot object
    2. QwtPlot myPlot;
    3. myPlot.setTitle( "Autospektrum!" );
    4. myPlot.setAxisTitle( QwtPlot::xBottom, "frequency bin" );
    5. myPlot.setAxisTitle( QwtPlot::yLeft, "log Amplitude" );
    6. myPlot.setCanvasBackground( QColor( Qt::darkBlue ));
    7.  
    8. // grid
    9. grid.enableXMin(true);
    10. grid.setMajPen( QPen( Qt::white, 0, Qt::DotLine ));
    11. grid.setMinPen( QPen( Qt::gray, 0 , Qt::DotLine ));
    12. grid.attach( &myPlot );
    13.  
    14. // define the curve object
    15. curve.setSamples( pXData, pResults, FFT_LENGTH );
    16. curve.setPen( QPen( Qt::yellow ));
    17. curve.setRenderHint( QwtPlotItem::RenderAntialiased );
    18. curve.setLegendAttribute( QwtPlotCurve::LegendShowLine );
    19. curve.attach( &myPlot );
    20.  
    21. // legend
    22. QwtLegend legend;
    23. legend.setItemMode( QwtLegend::ReadOnlyItem );
    24.  
    25. QwtLegendItem legendItem;
    26. legendItem.setText( QwtText( "Autospektrum" ));
    27. myPlot.insertLegend( &legend, QwtPlot::RightLegend );
    28.  
    29. myPlot.replot();
    30. myPlot.show();
    To copy to clipboard, switch view to plain text mode 

  2. #2
    Join Date
    Nov 2007
    Posts
    55
    Thanks
    1
    Thanked 9 Times in 9 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: qwt6.0.1 legend problem

    ich habe inzwischen weiter experimentiert. Füge ich
    Qt Code:
    1. legendItem.setVisible( true );
    To copy to clipboard, switch view to plain text mode 
    hinzu, wird ein neues Fenster geöffnet mit dem Text der Legende, aber ohne Kurvenlinie.
    Wer kann Hilfestellung leisten, da ich keine Lösung sehe, ich bin genau so vorgegangen wie im Beispiel BodePlot?
    Danke!

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

    Default Re: qwt6.0.1 legend problem

    First of all you should modify your code so that all of your widgets ( maybe beside a top level widget in main ) and plot items are allocated by new.
    Then show your main and how the code above is called.

    Uwe

  4. #4
    Join Date
    Nov 2007
    Posts
    55
    Thanks
    1
    Thanked 9 Times in 9 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: qwt6.0.1 legend problem

    I have had time to further look at my problem and find the solution.
    In reality I didn´t see that the line of the curve within the legend was plotted, because the line has a light yellow colour and the background is light gray. The line is also very short.
    I added a curve title which is now displayed as assumed and so fix the view onto the legend.
    I have attached the revised code below.

    Uwe, I am aware that in a normal case it is necessary to allocate the memory on the heap, this was a fast evaluation how to mix SigLib and Qwt, and I only had a main function, so allocating on the stack was OK for that peculiar purpose.
    Anyway, now I am going to clone the SigLib graphics function written with SignalVisualize/wxWidgets with Qt/Qwt, and there of course I´ll use the approach recommended by you.
    Qt Code:
    1. // plot object
    2. QwtPlot myPlot;
    3. myPlot.setTitle( "Autospektrum!" );
    4. myPlot.setAxisTitle( QwtPlot::xBottom, "frequency bin" );
    5. myPlot.setAxisTitle( QwtPlot::yLeft, "log Amplitude" );
    6. myPlot.setCanvasBackground( QColor( Qt::darkBlue ));
    7.  
    8. // grid
    9. grid.enableXMin( true );
    10. grid.setMajPen( QPen( Qt::white, 0, Qt::DotLine ));
    11. grid.setMinPen( QPen( Qt::gray, 0 , Qt::DotLine ));
    12. grid.attach( &myPlot );
    13.  
    14. // define the curve object
    15. QwtPlotCurve curve;
    16. curve.setSamples( pXData, pResults, FFT_LENGTH );
    17. curve.setPen( QPen( Qt::yellow ));
    18. curve.setRenderHint( QwtPlotItem::RenderAntialiased );
    19. curve.setTitle("Sinus");
    20. curve.setLegendAttribute( QwtPlotCurve::LegendShowLine );
    21. curve.attach( &myPlot );
    22.  
    23. // legend
    24. QwtLegend legend;
    25. myPlot.insertLegend( &legend, QwtPlot::RightLegend );
    26.  
    27. //myPlot.replot();
    28. myPlot.show();
    To copy to clipboard, switch view to plain text mode 

Similar Threads

  1. Problem with qwt6 and saving plot as image
    By discovery in forum Qwt
    Replies: 2
    Last Post: 12th November 2011, 19:18
  2. Legend manipulation
    By pkj in forum Qwt
    Replies: 1
    Last Post: 17th March 2011, 07:11
  3. Replies: 0
    Last Post: 18th August 2010, 02:21
  4. Replies: 1
    Last Post: 18th June 2010, 15:34
  5. Qwt Legend
    By maxpayne in forum Qwt
    Replies: 4
    Last Post: 15th October 2008, 17:17

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.