[英]Remove all canvas margins & spacing in Qwt
我有一个 QwtPlot,它包含在一个水平的 QwtPlotMultiBarChart 中。 我希望 canvas 高度、y 轴长度和条形图高度都相同。 我尝试将所有边距/间距设置为零并切换布局策略。
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);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.