I have a QwtPlot which consists in a single horizontal QwtPlotMultiBarChart. I would like to have the canvas height, the y axis length and the barchart height to be all the same. I tried settings all margins/spacing to zero and switch layout policies.
seriesPlot = new QwtPlot(this);
seriesPlot->plotLayout()->setCanvasMargin(0);
seriesPlot->plotLayout()->setSpacing(0);
seriesPlot->canvas()->setSizePolicy(QSizePolicy::Minimum, QSizePolicy::Minimum);
seriesPlot->canvas()->setContentsMargins(0,0,0,0);
d_barChartItem = new QwtPlotMultiBarChart();
d_barChartItem->setLayoutPolicy( QwtPlotMultiBarChart::ScaleSampleToCanvas );
d_barChartItem->setStyle( QwtPlotMultiBarChart::Stacked );
d_barChartItem->attach( seriesPlot );
populate();
d_barChartItem->setSpacing(0);
d_barChartItem->setMargin( 0 );
QwtPlot::Axis axis2 = QwtPlot::xBottom;
QwtPlot::Axis axis1 = QwtPlot::yLeft;
d_barChartItem->setOrientation( Qt::Horizontal );
seriesPlot->setAxisScale( axis1,-0.2,0.2 );
seriesPlot->setAxisAutoScale( axis2 );
QwtScaleDraw *scaleDraw1 = seriesPlot->axisScaleDraw( axis1 );
scaleDraw1->enableComponent( QwtScaleDraw::Backbone, false );
scaleDraw1->setSpacing(0);
scaleDraw1->enableComponent( QwtScaleDraw::Ticks, false );
scaleDraw1->enableComponent( QwtScaleDraw::Labels, false );
QwtScaleDraw *scaleDraw2 = seriesPlot->axisScaleDraw( axis2 );
scaleDraw2->enableComponent( QwtScaleDraw::Backbone, false );
scaleDraw2->enableComponent( QwtScaleDraw::Ticks, true );
seriesPlot->plotLayout()->setAlignCanvasToScale( axis1, true);
seriesPlot->updateAxes();
seriesPlot->plotLayout()->setCanvasMargin( 0 );
seriesPlot->updateCanvasMargins();
seriesPlot->updateLayout();
seriesPlot->replot();
seriesPlot->setAutoReplot( true );
And here is a picture of the two margins that i would like to remove:
I found the solution:
d_barChartItem->setLayoutHint(0.75);