1 Attachment(s)
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?)?
Code:
#include "mainwindow.h"
#include "ui_mainwindow.h"
#include <QLayout>
#include <qwt_plot.h>
MainWindow
::MainWindow(QWidget *parent
) , ui(new Ui::MainWindow)
{
ui->setupUi(this);
upperPlot->setAxesCount(0, 4);
upperPlot->setMinimumSize(10,10);
lowerPlot->setMinimumSize(10,10);
lowerLayout->setContentsMargins(0, 0, 0, 0);
lowerLayout->addWidget(lowerPlot);
mainLayout->addWidget(upperPlot);
mainLayout->addWidget(lowerWidget);
setCentralWidget(upperWidget);
}
MainWindow::~MainWindow()
{
delete ui;
}
int dx = upperPlot->canvas()->x() - lowerPlot->canvas()->x();
lowerLayout->insertSpacing(0, 1.3*dx);
}
Attachment 13493
Re: multiple QwtPlot alignement
Maybe have a look at the plotmatrix example ?
Uwe
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...
Re: multiple QwtPlot alignement
Quote:
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?
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