我有一个带 qwtplot 的 TimeGraph 类。此 qwtplot 显示在 QGraphicsView 上。qwtplot 有方法 resize en resizeEvent 但我不明白如何使用它们。
TimeGraph::TimeGraph(QWidget* parent, int in_display_time, QwtText title)
{
display_time = in_display_time;
graph.setParent(parent);
graph.setFixedSize(parent->width() - 20, parent->height() - 20);
graph.move(QPoint(10, 10));
grid.attach(&graph);
curve.attach(&graph);
curve.setPen(QPen(Qt::red, 2));
curve.setRenderHint(QwtPlotItem::RenderAntialiased);
if (title.text() != NULL)
graph.setTitle(title);
graph.setAxisScaleDraw(QwtPlot::xBottom, new TimeScaleDraw(QDateTime(QDate(0, 0, 0), QTime(0, 0, 0, 0))));
graph.setAxisScale(QwtPlot::xBottom, - display_time, 0);
graph.setAxisLabelRotation(QwtPlot::xBottom, -20.0);
graph.setAxisLabelAlignment(QwtPlot::xBottom, Qt::AlignLeft | Qt::AlignBottom);
graph.show();
}
和标题
struct Data { QVector<double> x; QVector<double> y;};
class TimeGraph
{
private :
QwtPlot graph;
QwtPlotCurve curve;
QwtPlotGrid grid;
Data data;
int display_time;
public:
TimeGraph(QWidget* parent, int in_display_time, QwtText title = QwtText());
void addPoint(QDateTime date, double y);
void resize(QRect zone);
};
我创建我的图表是这样的:
graph_O2 = new TimeGraph(ui->graphicsView_graph_o2, 120);
当 graphicsView 被调整大小时,我会调整自己的图形大小。我该怎么办?