Not Drawing QWT Plot Axis

早过忘川 提交于 2019-12-24 12:24:40

问题


I'm trying to draw a plot using QWT without any title or axis labels. Not drawing the title seems easy, all you have to do is not pass it in a title, or if there already is one, just give it an empty string (like this):

ui->plot->setAxisTitle(QwtPlot::xBottom, "");
ui->plot->setAxisTitle(QwtPlot::yLeft, "");

But the actual labels (inside the axisScale property) are drawn by default (going from 0 to 1000 in both x and y). However even though I can change the way it looks, I can't remove it altogether.

So is there any way to draw a qwt plot without any axis labels or titles?


回答1:


If you don't want the scale or the labels, this will work:

ui->plot->enableAxis(QwtPlot::xBottom, false);
ui->plot->enableAxis(QwtPlot::yLeft, false);

If you want to show the scales with no labels, you can implement your own QwtScaleDraw object that returns an empty QwtText object for all of the labels:

class MyScaleDraw : public QwtScaleDraw
{
public:
    MyScaleDraw() : QwtScaleDraw() { }
    virtual ~MyScaleDraw() { }
    virtual QwtText label(double) const
    {
        return QwtText();
    }
};

//...

ui->plot->setAxisScaleDraw(Qwt::xBottom, new MyScaleDraw);
ui->plot->setAxisScaleDraw(Qwt::yLeft, new MyScaleDraw);

There may be a better way, but this is one I could think of.




回答2:


I did the following: ui->plot->enableAxis(QwtPlot::yLeft, false);

But what happened is that my axis disappeared, but my plot is also squished into a thin horizontal bar.

What could cause this?




回答3:


Just found a nice way to do this:

ui->plot->axisScaleDraw(QwtPlot::xBottom)->enableComponent(QwtAbstractScaleDraw::ScaleComponent::Labels, false);

Also works with the ScaleComponents Ticks and Backbone.



来源:https://stackoverflow.com/questions/11872787/not-drawing-qwt-plot-axis

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!