问题
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