我有一個類的TimeGraph與qwtplot。 此qwtplot顯示在QGraphicsView上。 qwtplot的方法resize en resizeEvent但我不明白如何使用它們。在QGraphicsView QwtPlot調整大小
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 =新TimeGraph(UI-> graphicsView_graph_o2,120);
我會調整圖形大小調整自己的圖形大小。 我該怎麼辦?
不,qwt圖不一定真的在QGraphicsWiew上。但我不知道該怎麼做。我的qwt圖必須由代碼創建,因爲QtDesigner的插件qwt不適用於我的版本。沒有QGraphicsView如何將我的情節放置在我想要的QGroupBox中? – artoon
我對示例做了另一個回答(參見上文) – evilruff
好的,我的Widget中有我的TimeGraph。現在,我的類TimeGraph必須繼承QWidget嗎?並重新定義paintEvent? – artoon