Results 1 to 11 of 11

Thread: A way to align different QwtPlot objects?

  1. #1
    Join Date
    Mar 2010
    Posts
    319
    Thanks
    1
    Thanked 14 Times in 12 Posts
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows

    Default A way to align different QwtPlot objects?

    I have several QwtPlot objects, which are used to plot something against time. Now, the scale of that something can vary, meaning that the labels used to render the Y axis can be different from one QwtPlot object to another, and this results in the length of the X axis of my QwtPlot objects being different too. An example of what I am talking about can be seen here (ignore the red "OV"; the screenshot was annotated by a colleague of mine).

    That difference in length of the X axis of my different QwtPlot objects is clearly not neat. I was therefore wondering whether there would be a way to ensure that they are all of the same length?

    Cheers, Alan.

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

    Default Re: A way to align different QwtPlot objects?

    This has been asked and answered many times - check the forum and/or have a look at the plotmatrix example.

    Uwe

  3. #3
    Join Date
    Mar 2010
    Posts
    319
    Thanks
    1
    Thanked 14 Times in 12 Posts
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: A way to align different QwtPlot objects?

    I did check, but clearly not using the right keywords. Anyway, thanks for the tip, I am going to check the plotmatrix example.

  4. #4
    Join Date
    Jun 2014
    Posts
    17
    Thanks
    1
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows Android

    Default Re: A way to align different QwtPlot objects?

    plotmatrix gives a useful.

    But further problem is Y-axis (left or right) title. For long string with several words it can occupy >=1 lines, so the plots might be unaligned again. E.g. first plot has 1 line Y-axis title and second plot has 2 lines Y-axis.

    How is it possible to disable wrapping of axis titles? Or, may be other way?

    Thanks.


    Added after 37 minutes:


    Obviously, title font (size, family, etc.) also affects on title width. How is it possible to specify title width for QwtScaleWidget internal layout?

    I think it will be amazing if a QwtPlot will have a feature for such alignment with other plot:

    QList<QwtPlot*> layoutSyncingPlots(); // all syncing plots
    void QwtPlot::addLayoutSyncingPlot(const QwtPlot& other);

    In that 'layout syncing' group each plot tracks other plots and best syncing layout is found and applied for all plots in the group after any scale or size change. Of course, that syncing maybe better to implements through a dedicated separate class.
    Last edited by Alekon; 30th June 2015 at 11:05.

  5. #5
    Join Date
    Jun 2014
    Posts
    17
    Thanks
    1
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows Android

    Default Re: A way to align different QwtPlot objects?

    PlotAlign.png
    In the attach there are two plots with left-aligned X-axises (using "plotmatrix" example's way). How to align right axises? Note, that the plots differ by legend sizes and using/not using right Y-axis.

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

    Default Re: A way to align different QwtPlot objects?

    You could try to align the legend by manipulating the sizeHints of the legend items ( maybe by overloading QwtLegend::createWidget() ). Another option is not to insert the legends into the plot layout ( QwtPlot::insertLegend() ) and to put it into a QGridLayout instead.

    Uwe

  7. #7
    Join Date
    Jun 2014
    Posts
    17
    Thanks
    1
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows Android

    Default Re: A way to align different QwtPlot objects?

    Thanks a lot. Solved the problem by suitable for my requirements way. Legend was aligned with sizeHint() overriding; scales were aligned with adding fake invisible right Y-axis to the plot that has no right Y-axis. Now, it looks like this (attach). If someone interest the solution I can share the details.
    PlotAlign2.png

  8. #8
    Join Date
    Jun 2014
    Posts
    17
    Thanks
    1
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows Android

    Default Re: A way to align different QwtPlot objects?

    I have encountered a problem. Under some size the legend does not placed in right side, there is a gap appears (see attach). The plot is brushed as follows:
    qwtpltMain_->setAutoFillBackground(true);
    qwtpltMain_->setBackgroundRole(QPalette:ark);
    PlotAlign3.png

  9. #9
    Join Date
    Jun 2014
    Posts
    17
    Thanks
    1
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows Android

    Default Re: A way to align different QwtPlot objects?

    Hello Uwe,

    I'm using Qwt 6.1.0. Please look QwtPlotLayout::layoutLegend() (line 775) and QwtPlotLayout::LayoutData::init() (line 85) routings. It seems that there is twice compensation of legend width (vertical legends are considered) by value "legend.hScrollExtent". Is it right?

    Thanks

    ... as an option to explore the problem quickly I patched QwtLegend::scrollExtent() to permanently return 0 regardless of a scrollbar need, so twice compensation becomes "masked". It works as I expected - no extra width increasing. So, there is the twice compensation bug.
    Last edited by Alekon; 8th July 2015 at 12:17.

  10. #10
    Join Date
    Jun 2014
    Posts
    17
    Thanks
    1
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows Android

    Default Re: A way to align different QwtPlot objects?

    I have another issue (see attach). X-axis label (8000) on bottom plot shifts the plot canvas, so there is extra space between canves and legend. How can I "trim" scale widget to be under plot canvas without extents?

    Thanks.
    PlotAlign4.png

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

    Default Re: A way to align different QwtPlot objects?

    Quote Originally Posted by Alekon View Post
    It seems that there is twice compensation of legend width (vertical legends are considered) by value "legend.hScrollExtent". Is it right?
    Yes, I have added a bug report: https://sourceforge.net/p/qwt/bugs/241/

    Uwe


    Added after 4 minutes:


    Quote Originally Posted by Alekon View Post
    I have another issue (see attach). X-axis label (8000) on bottom plot shifts the plot canvas, so there is extra space between canves and legend. How can I "trim" scale widget to be under plot canvas without extents?
    The default setting is like this - your code seems to change it by setting QwtPlotLayout::setAlignCanvasToScale().

    Uwe
    Last edited by Uwe; 9th July 2015 at 08:39.

Similar Threads

  1. Replies: 1
    Last Post: 10th December 2014, 08:00
  2. How to align QwtScaleWidget with QwtPlot
    By mirrorrorrim in forum Qwt
    Replies: 6
    Last Post: 27th May 2013, 08:05
  3. Align vertically QwtPlot
    By Valsylver in forum Qwt
    Replies: 1
    Last Post: 4th August 2012, 13:44
  4. Align QwtSlider and QwtPlot
    By justoit in forum Qwt
    Replies: 4
    Last Post: 4th May 2011, 12:41
  5. Replies: 7
    Last Post: 18th July 2006, 22:33

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.