Results 1 to 3 of 3

Thread: Render canvas only to QImage

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Sep 2010
    Posts
    46
    Thanks
    14
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Question Render canvas only to QImage

    Hello,

    I have a regular plot with a spectrogram (with title, axis ticks, etc...).

    I need to render the plot canvas (without borders, axes, or anything else) to a QImage of a specific size (e.g. 512x512), for using it in QOpenGLTexture.
    The goal is to map the spectrogram image directly to a rectangle in OpenGL, with no empty spaces.

    I'm having trouble using QwtPlotRenderer for this task. The standard render() renders too much and there are empty spaces in canvas around the spectrogram as well. renderCanvas() requires a scale map which is rather confusing to me.

    Is there some easier way I'm missing?

    Thanks,
    Alexander

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

    Default Re: Render canvas only to QImage

    Quote Originally Posted by alex_sh View Post
    renderCanvas() requires a scale map which is rather confusing to me.
    If the data of your spectrogram is in the range 100-2000 on the bottom axis and 10-20 on the left axis and you want to render to a 500x500 image:

    Qt Code:
    1. QwtScaleMap maps[4];
    2.  
    3. maps[QwtPlot::xBottom].setPaintInterval( 0, 500 );
    4. maps[QwtPlot::xBottom].setScaleInterval( 100, 200 );
    5.  
    6. maps[QwtPlot::yLeft].setPaintInterval( 0, 500 );
    7. maps[QwtPlot::yLeft].setScaleInterval( 20, 10 );
    To copy to clipboard, switch view to plain text mode 
    Note that paint device coordinates are increasing from top to bottom, while y-scales usually have the smaller value at the bottom.

    HTH,
    Uwe

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

    alex_sh (9th February 2023)

  4. #3
    Join Date
    Sep 2010
    Posts
    46
    Thanks
    14
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Render canvas only to QImage

    This works like a charm.

    Thank you very much, Uwe!

Similar Threads

  1. Replies: 0
    Last Post: 24th October 2015, 16:25
  2. Replies: 0
    Last Post: 8th May 2014, 22:09
  3. QGLWidget render or QGraphicsView with GL viewport render
    By QTInfinity in forum Qt Programming
    Replies: 2
    Last Post: 28th November 2011, 12:34
  4. "Render" into QImage
    By Imons in forum Newbie
    Replies: 1
    Last Post: 29th March 2010, 14:45
  5. Replies: 3
    Last Post: 15th March 2006, 12:44

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.