Results 1 to 4 of 4

Thread: multiple QwtPlot alignement

  1. #1
    Join Date
    Nov 2019
    Posts
    29
    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,247
    Thanked 860 Times in 809 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
    29
    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?

Similar Threads

  1. Centralised data - multiple QwtPlot
    By Maximus2 in forum Qwt
    Replies: 2
    Last Post: 25th March 2014, 14:19
  2. QwtPlotRenderer for multiple QwtPlot
    By Momergil in forum Qwt
    Replies: 1
    Last Post: 18th January 2013, 11:09
  3. QwtPlot - multiple axis
    By MukundanAR in forum Qwt
    Replies: 1
    Last Post: 7th March 2012, 07:53
  4. QwtPlot - multiple axis
    By MukundanAR in forum Newbie
    Replies: 0
    Last Post: 6th March 2012, 11:50
  5. Replies: 1
    Last Post: 18th July 2011, 07: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.