首页 > 解决方案 > Qwt Plot:如何减少图例项之间的间距

问题描述

我发现 Qwt 图的图例中的行间距非常大。我想在图例中放置更多项目,而无需滚动并且不增加图例的大小。

有没有办法减少或删除图例中项目之间的间距?

编辑:

这是我得到的

这就是我想要的

这是一个示例代码,显示了我如何将曲线添加到图例中,然后显示在图例中。它并没有完全重现上面的情节,但显示了原理:

MainWindow::MainWindow(QWidget *parent) :
    QMainWindow(parent),
    ui(new Ui::MainWindow)
{
    ui->setupUi(this);

    QwtPlot* plot = new QwtPlot(this);
    setCentralWidget(plot);

    // Add curves
    for(int i=0; i<15; i++){
        QwtPlotCurve *curve = new QwtPlotCurve( "Curve " + QString::number(i) );
        curve->attach( plot );
        curve->setPen( Qt::blue, 2 );
        curve->setLegendAttribute( QwtPlotCurve::LegendShowLine );
    }

    // Add legend
    QwtLegend *legend = new QwtLegend();
    legend->setDefaultItemMode(QwtLegendData::Clickable); // make items clickable
    connect(legend, SIGNAL(clicked(const QVariant &, int)), this, SLOT(onLegendItemClicked(const QVariant &,int)) );        
    plot->insertLegend( legend, QwtPlot::LeftLegend );
}

如果我删除线

legend->setDefaultItemMode(QwtLegendData::Clickable);

图例项目之间的间距减小了一点(仍然没有我想要的那么小),但是当单击项目时不会发出 clicked(...) 信号。

知道如何在不失去可点击性的情况下减少间距吗?

标签: c++qtqwt

解决方案


推荐阅读