删除 Qwt 中的所有 canvas 边距和间距

Remove all canvas margins & spacing in Qwt

我有一个 QwtPlot,它由一个水平 QwtPlotMultiBarChart 组成。我希望 canvas 高度、y 轴长度和条形图高度都相同。我尝试将所有 margins/spacing 设置为零并切换布局策略。

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 );

这是我要删除的两个边距的图片:

我找到了解决方案:

d_barChartItem->setLayoutHint(0.75);