Results 1 to 3 of 3

Thread: How to subclass QwtPlotLayout in a useful way.

  1. #1
    Join Date
    Mar 2015
    Posts
    2
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11

    Default How to subclass QwtPlotLayout in a useful way.

    Hello,

    I had posted a feature request on the QWT project page (http://sourceforge.net/p/qwt/feature-requests/69/). I think I did not make myself totally clear. Therefore I want to continue the discussion here:


    What I want to do is to use a different plot layout for a QwtPlotSpectrogram. I want to force the plot canvas to be quadratic. I tried to subclass QwtPlotLayout and make one change in the method activate().

    From my understanding the class QwtPlotLayout is designed to be subclassed and the method activate() is designed to be overloaded.

    In the method activate() the layout is set by accessing d_data (e.g. d_data->canvasRect.setRect() ). I do not see how to do anything in an overloaded method activate() without access to d_data.

    If you have any ideas how to modify the method activate() in a class derived from QwtPlotLayout, please let me know.

    Best,
    Sebastian

  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: How to subclass QwtPlotLayout in a useful way.

    One hint before answering: you could have a look at QwtPlotRescaler. It offers to set an aspect ratio, what is not exactly, what you are asking for, but at least an easy way to avoid, that your image get stretched somehow. In playground/rescaler you find an example demonstrating how it works.

    About QwtPlotLayout: the implemented algo calculates the geometries for the legend, the scales an title/footer for a given rectangle first. The remaining rest is given to the canvas as being the only part that does not have any minimal requirements.

    But what you need is the other way round: the geometry for the canvas is given and you align the other widgets to it. ( See http://sourceforge.net/p/qwt/feature-requests/58 ). But this is more work than simply subcassing and modifying some coordinates - that's why I added this as a change request instead of simply doing it. But in case you want to work on it yourself you would have to explain which methods you would need to be accessible.

    So if QwtPlotRescaler is not good enough for you I would try to use QwtAbstractScaleDraw::setMinimumExtent() to have a stable size for the scales and then to set the geometry for the plot widget, that the canvas becomes square.

    Uwe

  3. #3
    Join Date
    Mar 2015
    Posts
    2
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11

    Default Re: How to subclass QwtPlotLayout in a useful way.

    Thanks for the answer.

    I first tried to use QwtPlotRescaler. However I could not figure out how to force it not to extend the axis range.

    Since I did not succeed in subclassing QwtPlotLayout, I copied the source code and renamed the whole class. Then I made my change in the function activate(). Actually the feature I was trying to accomplish works fine. I take the values that are used to set the canvas rect as maximum values. When I want the canvas to be quadratic, I just take the minimum of width and height and set this value as width and height of the canvas. When I want a non-quadratic canvas (e.g. when zooming), I set an aspect ratio and calculate width and height values for the canvas thereby respecting the maximum values.

    I can post the code lines if you like.

    All my attempts to change the geometry using size hints, resize commands or the like have not given good results.

Similar Threads

  1. Subclass QLabel
    By Globulus in forum Newbie
    Replies: 5
    Last Post: 29th July 2013, 21:30
  2. Replies: 2
    Last Post: 15th April 2013, 06:33
  3. How to subclass QAbstractProxyModel
    By skycrestway in forum Qt Programming
    Replies: 2
    Last Post: 22nd October 2010, 23:35
  4. Replies: 8
    Last Post: 12th February 2010, 02:41
  5. Subclass
    By merry in forum General Programming
    Replies: 2
    Last Post: 1st March 2007, 10:34

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.