PDA

View Full Version : QGraphicsView and QwtPlot



Indalo
16th November 2009, 05:02
Hello!

I'm trying to place a QwtPlot with QwtPlotSpectrogram on the QGraphicsView.

I took the standard example "spectrogram", adapted it for my needs. And my spectrogram successfully draws on QGraphicsView with QGraphicsScene, but one thing doesn't work well.

There is class MyZoomer in the example:


class MyZoomer: public QwtPlotZoomer
{
public:
MyZoomer(QwtPlotCanvas *canvas):
QwtPlotZoomer(canvas)
{
setTrackerMode(AlwaysOn);
}

virtual QwtText trackerText(const QwtDoublePoint &pos) const
{
QColor bg(Qt::white);
bg.setAlpha(200);

QwtText text = QwtPlotZoomer::trackerText(pos);
text.setBackgroundBrush( QBrush( bg ));
return text;
}
};

I made no changes in it, but it doesn't work when I place QwtPlot on the QGraphicsView.

I create Plot in the following way:


Plot* plot = new Plot(NULL, data, QCoreApplication::translate("QFrame", "Grid plot"));

And first parameter is the parent. It's null because:

1. If I pass my QGraphicsView* view I will get error (cannot convert from QGraphicsView to QWidget).
2. If I pass the main window pointer QwtPlot won't be showed at all.

I suppose this is the reason why zooming doesn't work.

What should I do?

Thanks a lot.

Indalo
16th November 2009, 07:17
In short, the problem is: zooming doesn't work when placing QwtPlot object in QGraphicsScene and drawing it on QGraphicsView.