Results 1 to 4 of 4

Thread: QwtPlotRenderer and ExternalLegend position

  1. #1
    Join Date
    Dec 2010
    Location
    Israel
    Posts
    90
    Thanks
    59
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default QwtPlotRenderer and ExternalLegend position

    I have a plot that uses a legend positioned initially with QwtPlot::RightLegend and then set to QwtPlot::ExternalLegend.

    I want to render the plot to the clipboard but the legend rectangle ends up being painted at position 0,0 and not where I actually see it in my widget.

    Here's the rendering code:
    Qt Code:
    1. QClipboard *clipboard = QApplication::clipboard();
    2. QwtPlotRenderer renderer;
    3. QImage img(this->size(), QImage::Format_ARGB32);
    4. QPainter painter(&img);
    5. renderer.render(this, &painter, this->rect());
    6. clipboard->setImage(img);
    To copy to clipboard, switch view to plain text mode 

    I tried to reposition the legend to QwtPlot::RightLegend but then I naturally get it in the separate right section as you would see it in the widget, which is not what I want.

    How can I make the legend rectangle painted in it's actual position?

  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: QwtPlotRenderer and ExternalLegend position

    QwtPlotRenderer::render() doesn't include an external legend - instead you have to calculate the layout for the legend in your application code ( like you do it with the legend widget ) and call QwtPlotRenderer::renderLegend() manually.

    Uwe

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

    frankiefrank (28th November 2011)

  4. #3
    Join Date
    Dec 2010
    Location
    Israel
    Posts
    90
    Thanks
    59
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: QwtPlotRenderer and ExternalLegend position

    Thanks for your reply. In my case the legend was indeed rendered although it was defined as ExternalLegend, is that a bug or did I misunderstand the expected behavior you describe?

    I understand I can renderLegend separately but maybe I'm missing QPainter experience, could you please direct me to how I can modify my code to render the legend separately in a position of my choosing? (for example (100,100)) ?

    Thanks as always for your attention and reply,
    Frankie

  5. #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: QwtPlotRenderer and ExternalLegend position

    Come on:

    Qt Code:
    1. QPainter painter(&img);
    2. renderer.render(plot, &painter, ... );
    3. renderer.renderLegend( plot, &painter, QRectF( 100, 100, ..., ... ) );
    To copy to clipboard, switch view to plain text mode 
    Uwe

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

    frankiefrank (29th November 2011)

Similar Threads

  1. Get GPS Position with QML
    By jgaleanog in forum Qt for Embedded and Mobile
    Replies: 1
    Last Post: 4th August 2011, 11:41
  2. Problems with QwtPlotRenderer from Qwt 6
    By mariposa in forum Qwt
    Replies: 24
    Last Post: 6th October 2010, 13:08
  3. How to get the mouse's position
    By sophister in forum Qt Programming
    Replies: 2
    Last Post: 30th April 2009, 06:07
  4. How to get mouse's position?
    By coralbird in forum Newbie
    Replies: 4
    Last Post: 23rd July 2006, 03:52
  5. set Position
    By mickey in forum Newbie
    Replies: 3
    Last Post: 17th June 2006, 21:30

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
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.