Results 1 to 3 of 3

Thread: plotmatrix canvas size after rescale

  1. #1
    Join Date
    Jun 2013
    Posts
    2
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows

    Default plotmatrix canvas size after rescale

    Hi all.

    I'm playing with Qwt and having some trouble with the plotmatrix example. In the example, I added a line in the MainWindow constructor after the calls to setAxisScale, as follows:

    Qt Code:
    1. setAxisScale(QwtPlot::yLeft, 2, -2, 2);
    To copy to clipboard, switch view to plain text mode 

    which calls setScaleAxis on the leftmost plot in the bottom row with limits -2 and 2. When I run the program, the scale comes out right, but the bottom row of plots is taller than the other rows. A screenshot is attached. What I want is for all the plots in the matrix to have the same size. How can I acheive that?

    Thanks.
    Attached Images Attached Images

  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: plotmatrix canvas size after rescale

    The size hints of a plot widget depend on its tick labels - guess this is the reason, why the grid layout acts this way. Try to change the size policies of the plot, if this doesn't work you have to derive from QwtPlot and overload minimumSizeHint()/sizeHint().

    See QWidget::setSizePolicy(), QWidget::sizeHint(), QWidget::minimumSizeHint().

    Uwe

  3. #3
    Join Date
    Jun 2013
    Posts
    2
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: plotmatrix canvas size after rescale

    Thanks for the input. I fiddled with the size policies on the plots, but I wasn't able to get anywhere with that. I also derived from QwtPlot and overrode the size hints. That seemed promising, but it was still doing unexpected things. In the end I decided to just lay out the plots by hand in my application. The tricky part was figuring out how much space would be taken up by the axes. In the end I settled on
    Qt Code:
    1. void PlotStack::resizeEvent(QResizeEvent* ev)
    2. {
    3. int w = width();
    4. int h = height();
    5.  
    6. QList<QwtPlot*> plots = findChildren<QwtPlot*>();
    7. int n = plots.size();
    8.  
    9. QwtPlot* last = plots.at(n-1);
    10.  
    11. // Figure out how much space is used by the axis
    12. QwtScaleWidget* scaleWidget = last->axisWidget(QwtPlot::xBottom);
    13. QwtScaleDraw* sd = scaleWidget->scaleDraw();
    14. sd->setMinimumExtent(0);
    15. int extent = sd->extent(scaleWidget->font());
    16. extent += scaleWidget->spacing();
    17. h -= extent;
    18.  
    19. // Resize all plots except the bottom
    20. for (int i = 0; i < n-1; ++i) {
    21. QwtPlot* plot = plots.at(i);
    22. plot->setGeometry(0, h / n * i, w, h / n);
    23. plot->replot();
    24. }
    25.  
    26. // Resize the bottom plot
    27. last->setGeometry(0, h / n * (n-1), w, h / n + extent);
    28. last->replot();
    29.  
    30. alignLeftAxes();
    31. }
    To copy to clipboard, switch view to plain text mode 

    I'm not sure this is quite right, but the plots look good.

    Thanks again.

Similar Threads

  1. Set size of QwtPlot/canvas
    By Hudo in forum Qwt
    Replies: 0
    Last Post: 23rd August 2012, 19:10
  2. How to rescale the QwtPlotZoomer->canvas
    By revellix in forum Qwt
    Replies: 6
    Last Post: 7th October 2011, 13:30
  3. QwtPlot Canvas Size Hint?
    By umituzun84 in forum Qwt
    Replies: 8
    Last Post: 22nd September 2011, 16:21
  4. canvas size
    By gkarthick5 in forum Qwt
    Replies: 3
    Last Post: 20th July 2011, 06:57
  5. Automatic rescale QwtPlotMarker
    By gpsgek in forum Qwt
    Replies: 0
    Last Post: 23rd May 2010, 16:26

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.