Results 1 to 6 of 6

Thread: how to customize the legend postion,so that i can bring the legends inside the plot?

  1. #1
    Join Date
    Feb 2010
    Posts
    28
    Qt products
    Qt4
    Platforms
    Windows

    Question how to customize the legend postion,so that i can bring the legends inside the plot?

    Hi Friends,

    i need to create the custom legend ... so that i can bring the legends inside the plot canvas....

    that means i wanted to change the Qwt Legend Position as per my wish...but By default Qwt provide the legend postions( LeftLegend,
    RightLegend,
    BottomLegend,
    TopLegend,

    ExternalLegend)......


    i am creating the legend by :

    insertLegend(new QwtLegend(), QwtPlot::RightLegend);

    defaultcurve->setLegendAttribute(QwtPlotCurve::LegendShowLine,t rue);
    defaultcurve->setLegendAttribute(QwtPlotCurve::LegendShowSymbol ,true);



    please go through the "gnuplot.png & qwtplot.png" image files...

    my client want exactly the same legend location as it in the "gnuplot.png"...

    so to achieve this what i need to do?... as well as i wanted to increase the length of the legend line

    i need to overload the qwt legend class????? or qwt legend item class??

    please provide some code example... that will be highly helpful...

    Thanks,
    Muthu
    Attached Images Attached Images

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

    Default Re: how to customize the legend postion,so that i can bring the legends inside the pl

    Don't crosspost !

    Uwe

  3. #3
    Join Date
    Feb 2010
    Posts
    28
    Qt products
    Qt4
    Platforms
    Windows

    Thumbs up Re: how to customize the legend postion,so that i can bring the legends inside the pl

    Hi Uwe,

    sorry for cross posting...

    and i have found the solution...

    my solution is:

    i create the custom legend and set the geometry inside the plot canvas..


    QwtLegend *customLegend = new QwtLegend(this);
    insertLegend(customLegend, QwtPlot::ExternalLegend);
    customLegend->setGeometry(QRect(70,30,120,100));
    customLegend->setMaximumWidth(120);
    customLegend->setMinimumWidth(120);
    customLegend->setMaximumHeight(100);
    customLegend->setMinimumHeight(100);

    this works perfectly.... and while save the plot into png file format ... i overload the QwtPlotRenderer functions

    void renderCanvas( const QwtPlot *plot,QPainter *painter, const QRectF &canvasRect,const QwtScaleMap* maps ) const;

    and

    void renderLegend(const QwtPlot *plot, QPainter *painter, const QRectF &rect) const;

    now it saves the *.png file with legends inside the plot canvas....this is exactly what i wanted to achieve...

    i am attaching the newly created qwtplot_new.png.....

    Thanks and Regards,
    Muthulingam
    Attached Images Attached Images

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

    Default Re: how to customize the legend postion,so that i can bring the legends inside the pl

    Qt Code:
    1. QwtLegend *customLegend = new QwtLegend(this);
    2. insertLegend(customLegend, QwtPlot::ExternalLegend);
    3. customLegend->setGeometry(QRect(70,30,120,100));
    To copy to clipboard, switch view to plain text mode 
    Assuming, that the position of the legend is supposed to be relative to the canvas and "this" is the plot widget itself:

    Install an event filter for the plot canvas and adjust position of your legend for each QEvent::Move event. Otherwise the legend will jump f.e when you zoom in and the tick labels of the scales need more or less space.

    Also use the the sizeHint of the legend for finding its geometry. Otherwise your layout might break when running in an environment f.e. with different fonts.

    Qt Code:
    1. customLegend->setMaximumWidth(120);
    2. customLegend->setMinimumWidth(120);
    3. customLegend->setMaximumHeight(100);
    4. customLegend->setMinimumHeight(100);
    To copy to clipboard, switch view to plain text mode 
    These lines are completely pointless, when you resize the legend with setGeometry yourself.

    Uwe

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

    frankiefrank (23rd January 2012)

  6. #5
    Join Date
    Feb 2009
    Posts
    51
    Thanks
    2
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: how to customize the legend postion,so that i can bring the legends inside the pl

    Hi Muthulingam,

    I am trying to do exactly what you did and having problem inserting items (lines with icon) into legend. Could you show me how to achieve that?

    Thank you

    --

    Never mind. I have figured it out.
    Thank you so much for your wonderful post.
    Last edited by jwieland; 25th October 2012 at 20:09.
    Sincerely,

    Wieland J.

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

    Default Re: how to customize the legend postion,so that i can bring the legends inside the pl

    Note that in Qwt from SVN trunk you have the option to use QwtPlotLegendItem instead of ( or additionally to ) the legend.

    Uwe

Similar Threads

  1. How to insert a legend in my plot?
    By paperflyer in forum Qwt
    Replies: 1
    Last Post: 7th October 2009, 17:04
  2. Qwt: How to create legends inside plots ?
    By Comer352l in forum Qwt
    Replies: 5
    Last Post: 16th August 2009, 18:02
  3. Sorting plot legend?
    By StefanK in forum Qwt
    Replies: 2
    Last Post: 5th April 2009, 19:29
  4. legend inside qwt plot
    By kaustav98255 in forum Qwt
    Replies: 5
    Last Post: 11th February 2009, 20:39
  5. Remove Legend items, move legends
    By giusepped in forum Qwt
    Replies: 0
    Last Post: 11th February 2009, 02:35

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.