Results 1 to 7 of 7

Thread: How to align QwtScaleWidget with QwtPlot

  1. #1
    Join Date
    May 2013
    Posts
    6
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11

    Default How to align QwtScaleWidget with QwtPlot

    I create a QGridlayout and place a QwtPlot in the center and four QwtScaleWidget at the side of Top, Bottom, Left, Right of the QwtPlot.
    And all the scales of QwtPlot itself are disabled by enableAxis( ..., false ).
    I initialized the four scales like below:
    scaleTop -> setScaleDiv( plot -> axisScaleDiv( QwtPlot::xTop ) );
    ...

    But it is found that the four scales are not matched with the plot.
    The value range of the scales is ok, but the ticks are not aligned with the grid of the plot.
    How could i do something to fix this?Thanks…

    If this is done, I will place several plots in grid and a lots of scales around all the plots.

    Just like below:

    blank scale scale
    scale plot plot
    scale plot plot
    blank scale scale
    Last edited by mirrorrorrim; 21st May 2013 at 10:07. Reason: updated contents

  2. #2
    Join Date
    Jan 2008
    Location
    Alameda, CA, USA
    Posts
    5,327
    Thanks
    317
    Thanked 871 Times in 858 Posts
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: How to align QwtScaleWidget with QwtPlot

    Your problem is probably that you are not setting the margins and / or the spacing in the grid layout to 0. All layouts automatically insert some extra space around the widgets inside them. In most cases, this leads to a pleasing layout. In this case, it leads to misalignment of the scales and plot. See QLayout::spacing(), QLayout::setContentsMargin(), QGridLayout::setHorizontalSpacing(), and QGridLayout::setVerticalSpacing().

    You will have to play around with it. If you want to have your 4 plot instances separated from each other (i.e. non-zero spacing between some, but not all widgets in the grid), you might have to embed layouts within layouts (for example, three vertical layouts inside a horizontal layout) instead of a single grid layout.

  3. #3
    Join Date
    May 2013
    Posts
    6
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11

    Default Re: How to align QwtScaleWidget with QwtPlot

    Quote Originally Posted by d_stranz View Post
    Your problem is probably that you are not setting the margins and / or the spacing in the grid layout to 0. All layouts automatically insert some extra space around the widgets inside them. In most cases, this leads to a pleasing layout. In this case, it leads to misalignment of the scales and plot. See QLayout::spacing(), QLayout::setContentsMargin(), QGridLayout::setHorizontalSpacing(), and QGridLayout::setVerticalSpacing().

    You will have to play around with it. If you want to have your 4 plot instances separated from each other (i.e. non-zero spacing between some, but not all widgets in the grid), you might have to embed layouts within layouts (for example, three vertical layouts inside a horizontal layout) instead of a single grid layout.

    I've set both the margins and spacing to be 0. But it still does not fix that.

    I noticed that all the scales of the plot itself which are enabled by enableAxis() do start from the point what has a small distance to the border. Cause I need them to be displayed as metioned, I have to disable all the scales provided by QwtPlot itself and new() them and place them in a grid layout and so I encounter this problem.

    It seems using QwtScaleWidget::setBorderDist( startDist, endDist ) may work on this situation. But I don't know how to give a suitable value for startDist. Or, shall I use scaleTop -> setScaleDiv( plot -> axisScaleDiv(...) ) to make the scales have the same value range of the plot? There is another way to initialize all the scales?

    d_stranz, thank you very much and wish you success in your work.
    This problem has perplexed me two weeks. Someone gives me a hand?
    Uwe...?

  4. #4
    Join Date
    May 2013
    Posts
    6
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11

    Default Re: How to align QwtScaleWidget with QwtPlot

    Uwe, can you help me?If there is a way I have not found or what else?
    If qwt can not support this, I have to give up and find another way to implement my application instead of qwt lib.

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

    Default Re: How to align QwtScaleWidget with QwtPlot

    You need to synchronize the coordinate system of the plot to the coordinate systems of your external scales - what means that the scale maps ( QwtScaleMap ) used for rendering the plot items have to be the same as those you are using for your external scale widgets.

    In your case I guess that the widget coordinates need to be adjusted ( translation between different widget coordinates ). f.e. by overloading QwtPlot::canvasMap().

    But I don't have enough information about your situation to tell you in detail what to do.

    Uwe

    PS: I will be offline the next days

  6. #6
    Join Date
    May 2013
    Posts
    6
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11

    Default Re: How to align QwtScaleWidget with QwtPlot

    Uwe,
    thank you so much and I'll try what you told me.
    Have good days.

  7. #7
    Join Date
    May 2013
    Posts
    6
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11

    Default Re: How to align QwtScaleWidget with QwtPlot

    Uwe
    I failed, so I decided to try another way based on Qt.
    Maybe I misunderstood your meanings.
    Thank you any way.

Similar Threads

  1. rotate QwtScaleWidget to horizontal
    By SamuelNLP in forum Qwt
    Replies: 2
    Last Post: 15th March 2013, 10:22
  2. Align vertically QwtPlot
    By Valsylver in forum Qwt
    Replies: 1
    Last Post: 4th August 2012, 12:44
  3. QGraphicsView & QwtScaleWidget
    By fruzzo in forum Qwt
    Replies: 1
    Last Post: 28th September 2011, 18:50
  4. Replies: 1
    Last Post: 19th July 2011, 07:32
  5. Align QwtSlider and QwtPlot
    By justoit in forum Qwt
    Replies: 4
    Last Post: 4th May 2011, 11:41

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
  •  
Qt is a trademark of The Qt Company.