PDA

View Full Version : Grid Minor Major and gap before the data



huseyinkozan
19th March 2009, 19:59
Hi,
This is the code in the constructor :


PlotWidget::PlotWidget(QWidget * parent, double * _ySession,
QString name, int rate, int numVis, int numSess)
: QwtPlot(parent) {
// data stuff....

QwtPainter::setDeviceClipping(false);
canvas()->setPaintAttribute(QwtPlotCanvas::PaintCached, true);
canvas()->setPaintAttribute(QwtPlotCanvas::PaintPacked, true);
//canvas()->setAttribute(Qt::WA_PaintOnScreen, true);
canvas()->setFrameStyle(QFrame::Box | QFrame::Plain);
canvas()->setLineWidth(1);
canvas()->setMidLineWidth(0);
setCanvasBackground(QColor(Qt::white));
enableAxis(QwtPlot::xBottom, false);
enableAxis(QwtPlot::yLeft, false);
setMargin(0);

setAxisScale(QwtPlot::xBottom,0.0, sizeLoop);
setAxisScale(QwtPlot::yLeft,1500, 3000, 0 );

setAxisMaxMajor(QwtPlot::yLeft, 8);
setAxisMaxMinor(QwtPlot::yLeft, 5);

QwtValueList vlist[3];
for(double i=0;i<sizeLoop; i+=((sizeLoop-0)/13*5))
vlist[0] << i;
for(double i=0;i<sizeLoop; i+=((sizeLoop-0)/13))
vlist[1] << i;
for(double i=0;i<sizeLoop; i+=((sizeLoop-0)/13))
vlist[2] << i;
QwtScaleDiv scdiv(0, sizeLoop, vlist);
setAxisScaleDiv(QwtPlot::xBottom, scdiv);

// for inside margin (I think)
axisScaleEngine(QwtPlot::xBottom)->setAttributes(QwtScaleEngine::Floating);
axisScaleEngine(QwtPlot::xTop)->setAttributes(QwtScaleEngine::Floating);
axisScaleEngine(QwtPlot::yLeft)->setAttributes(QwtScaleEngine::Floating);
axisScaleEngine(QwtPlot::yRight)->setAttributes(QwtScaleEngine::Floating);

curve = new QwtPlotCurve(name);
//curve->setRenderHint(QwtPlotItem::RenderAntialiased);
pen->setWidthF(penWidth + penWidthDiff);
curve->setPen(*pen);
curve->attach(this);
curve->setRawData(xLoop, yLoop, sizeLoop);

grid = new QwtPlotGrid;
grid->enableXMin(true);
grid->enableYMin(true);
gridMinPen = new QPen(QColor(255, 230, 230), 0, Qt::SolidLine, Qt::RoundCap, Qt::RoundJoin);
gridMajPen = new QPen(QColor(255, 200, 200), 0, Qt::SolidLine, Qt::RoundCap, Qt::RoundJoin);
grid->setMajPen(*gridMajPen);
grid->setMinPen(*gridMinPen);
grid->attach(this);
}


And the code in the derived print filter :


QColor MyQwtPlotPrintFilter::color(const QColor &c, Item item) const {
switch(item){
case MajorGrid:
return Qt::blue;
case MinorGrid:
return Qt::green;
default:;
}
return c;
}


I got the exported pdf as attached "export.pdf". But I want to get "expected.png".
I added the colors to see the major and minor grids.

Now, the problem is :
1) I cannot see the minor grids at x axis.
2) I dont want a gap between the starting data and plot edge.

For 2'nd I found :
axisScaleEngine(QwtPlot::xBottom)->setAttributes(QwtScaleEngine::Floating);
but I couldn't realize what the QwtScaleEngine::Floating means (and other Attribute's)

Thanks for help.


Hüseyin

Uwe
20th March 2009, 06:57
Now, the problem is :
1) I cannot see the minor grids at x axis.
2) I dont want a gap between the starting data and plot edge.

1) Are there any minor ticks in your bottom scale ?
2) plot->plotLayout()->setAlignCanvasToScales(true);

Uwe

huseyinkozan
20th March 2009, 13:00
1) Are there any minor ticks in your bottom scale ?
2) plot->plotLayout()->setAlignCanvasToScales(true);

Uwe

1) I found the QwtValueList model here : http://thread.gmane.org/gmane.comp.graphics.qwt.general/1425
Does this not assign the minor, medium and major ticks ?

2) I have added the code and plotLayout()->setCanvasMargin(...) it works.

Thanks.


Hüseyin

Note: I am using 5.1.2-svn, Qt 4.5 with msvc addin. And the code is here:

PlotWidget::PlotWidget(QWidget * parent, double * _ySession,
QString name, int rate, int numVis, int numSess)
: QwtPlot(parent)
{
setAutoReplot(false);
sampRate = rate;
plotName = name;
sizeLoop = numVis;
sizeVisible = numVis;
sizeSession = numSess;
scrollModeOn = false;
clearPlot = false;
indexLoop = 0;
sessionScrollIndex = 0;
pageDiv = 50;
xLoop = new double[sizeLoop];
yLoop = new double[sizeLoop];
ySession = _ySession;
pen = new QPen(Qt::black);
penWidth = 1.0;
penWidthDiff = 0.5;
gridMinPenWidth = 1.0;
gridMajPenWidth = 1.0;
for (int i = 0; i < sizeLoop; i++){
xLoop[i] = i;
yLoop[i] = 0.0;
}

QwtPainter::setDeviceClipping(false);
canvas()->setPaintAttribute(QwtPlotCanvas::PaintCached, true);
canvas()->setPaintAttribute(QwtPlotCanvas::PaintPacked, true);
//canvas()->setAttribute(Qt::WA_PaintOnScreen, true);
canvas()->setFrameStyle(QFrame::Box | QFrame::Plain);
canvas()->setLineWidth(1);
canvas()->setMidLineWidth(0);
setCanvasBackground(QColor(Qt::white));
enableAxis(QwtPlot::xBottom, false);
enableAxis(QwtPlot::yLeft, false);
setMargin(0);

setAxisScale(QwtPlot::xBottom,0.0, sizeLoop);
setAxisScale(QwtPlot::yLeft,1500, 3000, 0 );

setAxisMaxMajor(QwtPlot::yLeft, 8);
setAxisMaxMinor(QwtPlot::yLeft, 5);

QwtValueList vlist[3];
for(double i=0;i<sizeLoop; i+=((sizeLoop-0)/13*5))
vlist[0] << i;
for(double i=0;i<sizeLoop; i+=((sizeLoop-0)/13))
vlist[1] << i;
for(double i=0;i<sizeLoop; i+=((sizeLoop-0)/13))
vlist[2] << i;
QwtScaleDiv scdiv(0, sizeLoop, vlist);
scdiv.setTicks(QwtScaleDiv::MinorTick, vlist[1]);
setAxisScaleDiv(QwtPlot::xBottom, scdiv);

// for inside margin
plotLayout()->setAlignCanvasToScales(true);
plotLayout()->setCanvasMargin(0,QwtPlot::xBottom);
plotLayout()->setCanvasMargin(0,QwtPlot::xTop);
plotLayout()->setCanvasMargin(0,QwtPlot::yLeft);
plotLayout()->setCanvasMargin(0,QwtPlot::yRight);

curve = new QwtPlotCurve(plotName);
pen->setWidthF(penWidth + penWidthDiff);
curve->setPen(*pen);
curve->attach(this);
curve->setRawData(xLoop, yLoop, sizeLoop);

grid = new QwtPlotGrid;
grid->enableXMin(true);
grid->enableYMin(true);
gridMinPen = new QPen(QColor(255, 230, 230), 0, Qt::SolidLine, Qt::RoundCap, Qt::RoundJoin);
gridMajPen = new QPen(QColor(255, 200, 200), 0, Qt::SolidLine, Qt::RoundCap, Qt::RoundJoin);
grid->setMajPen(*gridMajPen);
grid->setMinPen(*gridMinPen);
grid->attach(this);

labelMarker = new QwtPlotMarker;
labelMarker->setValue(QwtDoublePoint(50, 2900));
QwtText text(plotName);
text.setFont(QFont("Verdana", 10, QFont::Bold));
text.setColor(QColor(180,180,180));
text.setRenderFlags(Qt::AlignLeft);
labelMarker->setLabel(text);
labelMarker->attach(this);
}

viridis
3rd August 2010, 12:13
Hi,

I don't want any spacing between the scale backbone and the canvas (plotting area). Thus, the backbones of the left and bottom axes should be "connected". I tried the following without success (there is a 1 or 2 pixels gap):



plotLayout()->setAlignCanvasToScales(true);
plotLayout()->setCanvasMargin(0, QwtPlot::xBottom);
plotLayout()->setCanvasMargin(0, QwtPlot::xTop);
plotLayout()->setCanvasMargin(0, QwtPlot::yLeft);
plotLayout()->setCanvasMargin(0, QwtPlot::yRight);
plotLayout()->setSpacing(0);
plotLayout()->setMargin(0);


Any hints?