Results 1 to 8 of 8

Thread: QwtPlot stretching

  1. #1
    Join Date
    Apr 2008
    Posts
    53
    Thanks
    10

    Default QwtPlot stretching

    Hi,

    I have a simple problem... I'm adding a QwtPlot to a QMainWindow's central widget. I was wondering how to keep the QwtPlot as a square (maintaining aspect ratio) instead of stretching whenever the mainWindow stretches?

    Thank you

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

    Default Re: QwtPlot stretching

    Try QwtPlotRescaler from Qwt 5.2.

    Uwe

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

    jmsbc (11th April 2009)

  4. #3
    Join Date
    Mar 2009
    Posts
    22
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QwtPlot stretching

    Quote Originally Posted by Uwe View Post
    Try QwtPlotRescaler from Qwt 5.2.

    Uwe
    And navigation example in the svn to learn how to use:
    http://qwt.svn.sourceforge.net/viewv...34&view=markup


    Hüseyin

  5. #4
    Join Date
    Apr 2008
    Posts
    53
    Thanks
    10

    Default Re: QwtPlot stretching

    Thanks for both of your help!

  6. #5
    Join Date
    Dec 2009
    Posts
    52
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: QwtPlot stretching

    I have tried with this code:
    Qt Code:
    1. QApplication& appref = app;
    2. QWidget window;
    3. window.setWindowTitle("...");
    4.  
    5. QwtPlot dataPlot(QwtText("..."), &window);
    6. dataPlot.setAxisTitle( QwtPlot::xBottom, "time" );
    7. dataPlot.setAxisTitle( QwtPlot::yLeft, "data" );
    8.  
    9. QwtPlotRescaler dataPlotRescaler(dataPlot.canvas());
    10. dataPlotRescaler.setReferenceAxis(QwtPlot::xBottom);
    11. dataPlotRescaler.setAspectRatio(QwtPlot::yLeft, 1.0);
    12. dataPlotRescaler.setAspectRatio(QwtPlot::yRight, 0.0);
    13. dataPlotRescaler.setAspectRatio(QwtPlot::xTop, 0.0);
    14.  
    15. window.connect(&dataPlot, SIGNAL(resized(double, double)), SLOT(showRatio(double, double)));
    16.  
    17. Data data(d);
    18. pc.setData(data);
    19. pc.attach(&dataPlot);
    20. dataPlot.replot();
    21. window.show();
    22. appref.exec();
    To copy to clipboard, switch view to plain text mode 
    This is taken from
    http://qwt.svn.sourceforge.net/viewv...34&view=markup

    which doesn't seem to exist in the examples in https://qwt.svn.sourceforge.net/svnr...anches/qwt-5.2

    The window that comes out is big, but the plot is small, in the top left corner.
    I wished to bind the plot to the whole window and resize the plot when I resize the window first. And then maybe change the scale of the axes when the plot is resized.

    rds,
    Last edited by hml; 20th December 2009 at 21:14.

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

    Default Re: QwtPlot stretching

    You need to add a layout for your window, where you add the plot widget ( or overload resizeEvent of widget and resize the plot manually ). But this is basic Qt and has not much to do with Qwt.

    The rescaler is responsible for adjusting the scales, when the plot is resized, but it doesn't resize the plot.

    Uwe

  8. #7
    Join Date
    Dec 2009
    Posts
    52
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: QwtPlot stretching

    That is what i was suspecting. I am new to Qt as well.
    Thanks very much for your answer,

  9. #8
    Join Date
    Apr 2013
    Posts
    63
    Thanks
    15
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: QwtPlot stretching

    Hi,
    I am trying the same thing. I have inherited a class from QWTPlot and inside that I am calling
    Qt Code:
    1. QwtPlotRescaler rescaler(canvas());
    2. rescaler.setReferenceAxis(QwtPlot::xBottom);
    3. rescaler.setAspectRatio(QwtPlot::yLeft, 1.0);
    To copy to clipboard, switch view to plain text mode 

    Initially my plot X,Y axes have same range,0 to 1. But My data changes such that y axis range is -1 to 1 keeping x axis range 0 to 1, my aspect ratio is changed. I expected that the plot will become a rectangle of height=2*width. But it remains as a square and Y axis got shrunk. I need to dynamically change the Y axis range and need to maintain aspect ratio. What I need to do?

Similar Threads

  1. QwtPlot - promote to custom widget
    By MrGarbage in forum Qwt
    Replies: 7
    Last Post: 10th February 2011, 10:12
  2. Replies: 2
    Last Post: 5th December 2008, 20:11
  3. Replies: 2
    Last Post: 28th March 2008, 17:03
  4. Replies: 3
    Last Post: 26th March 2008, 11:04
  5. connect qwtplot from ui with code
    By pospiech in forum Qwt
    Replies: 0
    Last Post: 9th March 2008, 17:00

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.