Results 1 to 5 of 5

Thread: multiple QwtPlot alignement

  1. #1
    Join Date
    Nov 2019
    Posts
    31
    Thanks
    8
    Qt products
    Qt5
    Platforms
    Unix/X11 Windows

    Default multiple QwtPlot alignement

    Hi,

    I'm trying to vertically align two QwtPlot. The upper plot has multiple Y-axis so these two plots should share the same X-axis position a limits.
    I've seen other solution but here is how I want to do that:
    QBoxLayout allows to insert spacing insertSpacing(int index, int size). So I get the x-canvas position of upper plot and of lower plot. Then calculate the difference between the and add this difference to lower plot via insertSpacing(int index, int size)
    the problem is that it works only if multiply this difference by 1.3 coeff then no matter how many Y-axis has upper plot, both plots "share the same X-axis". Why units of plot->canvas()->geometry() and QBoxLayout::insertSpacing(int index, int size) are different (why I need to multiply it?)?
    Qt Code:
    1. #include "mainwindow.h"
    2. #include "ui_mainwindow.h"
    3.  
    4. #include <QLayout>
    5. #include <qwt_plot.h>
    6.  
    7. MainWindow::MainWindow(QWidget *parent)
    8. : QMainWindow(parent)
    9. , ui(new Ui::MainWindow)
    10. {
    11. ui->setupUi(this);
    12.  
    13. upperPlot = new QwtPlot(this);
    14. lowerPlot = new QwtPlot(this);
    15. upperPlot->setAxesCount(0, 4);
    16. upperPlot->setMinimumSize(10,10);
    17. lowerPlot->setMinimumSize(10,10);
    18.  
    19. QWidget* upperWidget = new QWidget;
    20. QVBoxLayout* mainLayout = new QVBoxLayout(upperWidget);
    21.  
    22. QWidget* lowerWidget = new QWidget;
    23. lowerLayout = new QHBoxLayout(lowerWidget);
    24. lowerLayout->setContentsMargins(0, 0, 0, 0);
    25. lowerLayout->addWidget(lowerPlot);
    26.  
    27. mainLayout->addWidget(upperPlot);
    28. mainLayout->addWidget(lowerWidget);
    29.  
    30. setCentralWidget(upperWidget);
    31. }
    32.  
    33. MainWindow::~MainWindow()
    34. {
    35. delete ui;
    36. }
    37.  
    38. void MainWindow::showEvent(QShowEvent *event){
    39. int dx = upperPlot->canvas()->x() - lowerPlot->canvas()->x();
    40. lowerLayout->insertSpacing(0, 1.3*dx);
    41. }
    To copy to clipboard, switch view to plain text mode 
    1.jpg

  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: multiple QwtPlot alignement

    Maybe have a look at the plotmatrix example ?

    Uwe

  3. #3
    Join Date
    Nov 2019
    Posts
    31
    Thanks
    8
    Qt products
    Qt5
    Platforms
    Unix/X11 Windows

    Default Re: multiple QwtPlot alignement

    Hi Uwe,

    I just figured out that showEvent() is triggered when layout changes were not applied yet (100% sure). So this is inaproppriate method to set geometry for widgets.
    But there is QWidget::resizeEvent(QResizeEvent *event) where I'm going to write my code. It should work I hope...

  4. #4
    Join Date
    Jul 2020
    Posts
    1
    Qt products
    Qt5
    Platforms
    Android

    Default Re: multiple QwtPlot alignement

    Hi Uwe,

    I just figured out that showEvent() is triggered when layout changes were not applied yet (100% sure). So this is inaproppriate method to set geometry for widgets.
    But there is QWidget::resizeEvent(QResizeEvent *event) where I'm going to write my code. It should work I hope...
    Hello there
    I'm a newbie so chances are I am wrong but have you tried this code https://doc.qt.io/qt-5/qwidget.html#...Geometry-prop?

  5. #5
    Join Date
    Nov 2019
    Posts
    31
    Thanks
    8
    Qt products
    Qt5
    Platforms
    Unix/X11 Windows

    Default Re: multiple QwtPlot alignement

    Uwe,

    I'm still about vertical alignement of canvas of two plots.
    The problem is that these two plots may have any numbers of YAxis.

    I'm wondering is it possible to set each canvas of each plot to a one grid layout and axes should be in other cells of grid layout?
    Basiccaly I'm trying to split qwtPlot to elements (canvas, axis, legend) it consists of and set each element to a predefined cell of gridlayout.

    P.S. matrix example doesn't help much in this case
    Last edited by Vasya; 14th July 2020 at 16:41.

Similar Threads

  1. Centralised data - multiple QwtPlot
    By Maximus2 in forum Qwt
    Replies: 2
    Last Post: 25th March 2014, 15:19
  2. QwtPlotRenderer for multiple QwtPlot
    By Momergil in forum Qwt
    Replies: 1
    Last Post: 18th January 2013, 12:09
  3. QwtPlot - multiple axis
    By MukundanAR in forum Qwt
    Replies: 1
    Last Post: 7th March 2012, 08:53
  4. QwtPlot - multiple axis
    By MukundanAR in forum Newbie
    Replies: 0
    Last Post: 6th March 2012, 12:50
  5. Replies: 1
    Last Post: 18th July 2011, 08:56

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.