PDA

View Full Version : Scales alignment



fruzzo
19th September 2011, 16:08
Hi,
I have to dynamically align plot x-axis scale (so on, all plot) according to a slider scale, so that min/max scale values are vertically aligned (with respect to x display coordinates) such as in the following picture.
(i.e. plot min/max scale values have to change when I resize the slider by code).

6865

Do you have some idea how to reach this task? How can I get slider min/max scale values x position? Than, how can I set plot min/max scale values x position?

Uwe
20th September 2011, 13:07
Because of the layout concept implemented in QwtPlot It would be easier to align the scale of the slider.

Uwe

fruzzo
20th September 2011, 13:28
Because of the layout concept implemented in QwtPlot It would be easier to align the scale of the slider.

Uwe

Unfortunately I have other homemade chronograms in the same layout which its scales have to be aligned to the slider scale (.i.e. a time line slider) so this one is the master over other scales...Afterword, how I can change the plot scale in order to change its x-axis min/max?

fruzzo
22nd September 2011, 16:49
Changing the point of view...trying to align the scale of the slider, first of all I want to set a fixed size about the plot y-axis (i.e. y-scale-widget width) regardless of y-data inserted, how can I do this? scale widget extent is the number of pixel needed to represent the digits (documentation isn't so clear)?

sorry but I'm a newbie of qwt :)

fruzzo
26th September 2011, 15:50
Ok...I've implemented my new plot widget containing a standard qwtplot and a custom YScaleWidget with a fixed size connected through like suggest in another post.
This is my result:
6887

All works fine is I don't show e.g. x-bottom axis and plot title...my YScaleWidget height is the height of all qwtplot even if I use the plot->canvas()->geometry(), in order to find the right height of the canvas, inside the resizeEvent function of the container widget. I try to send a signal juast after the updateLayout is called with same result...why?

fruzzo
28th September 2011, 08:50
Solved...I created a custom layout inherited from QLayout, something like a QHBoxLayout where the Y scalewidget height is perfectly alligned to the Plot Y-Axis.

fruzzo
28th September 2011, 16:32
last questions:

1. Why are little different Plot1 vs Plot2 (with Y-Axis sclae widget disabled) regarding Y-Axis behaviour of plot canvas data painting?

69166917

2. If Y left Scale Widget is enabled setting canvas margin (e.g. plot->plotLayout()->setCanvasMargin(20, QwtPlot::xTop)) has effect on plot canvas data painting, besides if Y left Scale Widget is disabled setting canvas margin hasn't effect, why?

Below the code used to implement setGeometry of my custom layout (PlotLayout):

void MyPlotWidget::PlotLayout::setGeometry(const QRect &rect)
{
QLayout::setGeometry(rect);
if (myItemList.size() == 0)
return;

int w = rect.width() - (myItemList.count() - 1) * spacing();
int h = rect.height() - (myItemList.count() - 1) * spacing();

int scaleWidgetWidth = 0;
QLayoutItem * itemScaleWidget = NULL;
QLayoutItem * itemPlot = NULL;
for (int i=0; i<myItemList.size(); i++)
{
if (!itemScaleWidget && dynamic_cast<QwtScaleWidget *>(myItemList.at(i)->widget()))
{
itemScaleWidget = myItemList.at(i);
scaleWidgetWidth = myItemList.at(i)->geometry().width();
}
else if (dynamic_cast<QwtPlot *>(myItemList.at(i)->widget()))
{
itemPlot = myItemList.at(i);
itemPlot->setGeometry(QRect(rect.x() + scaleWidgetWidth + i * spacing(), rect.y() + i * spacing(), w - scaleWidgetWidth, h));
}
}

if (itemScaleWidget && itemPlot && dynamic_cast<QwtPlot *>(itemPlot->widget()))
{
QwtPlot * plot = dynamic_cast<QwtPlot *>(itemPlot->widget());
QRect scaleRect = itemScaleWidget->geometry();
QRect canvasRect = plot->plotLayout()->canvasRect();
QRect canvasRect2 = plot->canvas()->rect();
QRect canvasContRect2 = plot->canvas()->contentsRect();
int fw = plot->canvas()->frameWidth();
int marginTop = 0;
int marginBottom = 0;

if(!plot->plotLayout()->alignCanvasToScales ())
{
marginTop = plot->plotLayout()->canvasMargin(QwtPlot::xTop);
marginBottom = plot->plotLayout()->canvasMargin(QwtPlot::xBottom);
}
scaleRect.setTop(canvasRect.top() + fw + marginTop - plot->axisWidget(QwtPlot::yLeft)->startBorderDist());
scaleRect.setBottom(canvasRect.bottom() - fw - marginBottom - 1 + plot->axisWidget(QwtPlot::yLeft)->startBorderDist());

itemScaleWidget->setGeometry(scaleRect);
}
}