【问题标题】:Remove all canvas margins & spacing in Qwt删除 Qwt 中的所有画布边距和间距
【发布时间】:2021-05-20 10:46:54
【问题描述】:

我有一个 QwtPlot,它包含在一个水平 QwtPlotMultiBarChart 中。我希望画布高度、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 );

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

【问题讨论】:

    标签: c++ qt qt5 qwt


    【解决方案1】:

    我找到了解决办法:

    d_barChartItem->setLayoutHint(0.75);
    

    【讨论】:

      猜你喜欢
      • 2016-05-02
      • 1970-01-01
      • 2014-02-27
      • 2017-11-05
      • 2013-05-01
      • 2019-03-27
      • 1970-01-01
      • 2013-12-25
      • 1970-01-01
      相关资源
      最近更新 更多