Mam problem ze znalezieniem sposobu na obejście problemu przedstawionego poniżej
main.cpp
Kod: Zaznacz cały
#include <QtGui/QApplication>
#include "widget.h"
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
Widget w;
w.show();
return a.exec();
}
Kod: Zaznacz cały
#ifndef WIDGET_H
#define WIDGET_H
#include <QWidget>
#include <qwt_plot.h>
namespace Ui {
class Widget;
}
class Widget : public QWidget
{
Q_OBJECT
public:
explicit Widget(QWidget *parent = 0);
~Widget();
protected:
virtual void resizeEvent(QResizeEvent *);
private:
Ui::Widget *ui;
void populate();
void updateGradient(QwtPlot *);
};
#endif // WIDGET_H
Kod: Zaznacz cały
#include "widget.h"
#include "ui_widget.h"
#include <qapplication.h>
#include <qlayout.h>
#include <qwt_plot.h>
#include <qwt_plot_marker.h>
#include <qwt_plot_curve.h>
#include <qwt_legend.h>
#include <qwt_series_data.h>
#include <qwt_plot_canvas.h>
#include <qwt_plot_panner.h>
#include <qwt_plot_magnifier.h>
#include <qwt_text.h>
#include <qwt_math.h>
#include <math.h>
class FunctionData: public QwtSyntheticPointData
{
public:
FunctionData(double(*y)(double)):
QwtSyntheticPointData(100),
d_y(y)
{
}
virtual double y(double x) const
{
return d_y(x);
}
private:
double(*d_y)(double);
};
Widget::Widget(QWidget *parent) :
QWidget(parent),
ui(new Ui::Widget)
{
ui->setupUi(this);
ui->qwtPlot->setTitle("jakis wykres");
(void) new QwtPlotPanner (ui->qwtPlot->canvas() );
(void) new QwtPlotPanner (ui->qwtPlot->canvas() );
ui->qwtPlot->setAutoFillBackground(true);
ui->qwtPlot->setPalette( QPalette(QColor(165,193,228)));
updateGradient( ui->qwtPlot );
ui->qwtPlot->setTitle("wykres sinusa");
ui->qwtPlot->insertLegend(new QwtLegend(), QwtPlot::RightLegend);
// osie
ui->qwtPlot->setAxisTitle(ui->qwtPlot->xBottom , "X -->");
ui->qwtPlot->setAxisScale(ui->qwtPlot->xBottom , 0.0, 10.0);
ui->qwtPlot->setAxisTitle(ui->qwtPlot->yLeft, "y -->");
ui->qwtPlot->setAxisScale(ui->qwtPlot->yLeft, -1.0, 1.0);
// canvas
ui->qwtPlot->canvas()->setLineWidth( 1 );
ui->qwtPlot->canvas()->setFrameStyle( QFrame::Box | QFrame::Plain );
ui->qwtPlot->canvas()->setBorderRadius( 15 );
QPalette canvasPalette( Qt::white );
canvasPalette.setColor( QPalette::Foreground, QColor( 133, 190, 232 ) );
ui->qwtPlot->canvas()->setPalette( canvasPalette );
populate();
}
void Widget::populate(){
// Insert new curves
QwtPlotCurve *cSin = new QwtPlotCurve("y = sin(x)");
cSin->setRenderHint(QwtPlotItem::RenderAntialiased);
cSin->setLegendAttribute(QwtPlotCurve::LegendShowLine, true);
cSin->setPen(QPen(Qt::red));
cSin->attach(ui->qwtPlot);
QwtPlotCurve *cCos = new QwtPlotCurve("y = cos(x)");
cCos->setRenderHint(QwtPlotItem::RenderAntialiased);
cCos->setLegendAttribute(QwtPlotCurve::LegendShowLine, true);
cCos->setPen(QPen(Qt::blue));
cCos->attach(ui->qwtPlot);
// Create sin and cos data
cSin->setData(new FunctionData(::sin));
cCos->setData(new FunctionData(::cos));
// Insert markers
// ...a horizontal line at y = 0...
QwtPlotMarker *mY = new QwtPlotMarker();
mY->setLabel(QString::fromLatin1("y = 0"));
mY->setLabelAlignment(Qt::AlignRight|Qt::AlignTop);
mY->setLineStyle(QwtPlotMarker::HLine);
mY->setYValue(0.0);
mY->attach(ui->qwtPlot);
// ...a vertical line at x = 2 * pi
QwtPlotMarker *mX = new QwtPlotMarker();
mX->setLabel(QString::fromLatin1("x = 2 pi"));
mX->setLabelAlignment(Qt::AlignLeft | Qt::AlignBottom);
mX->setLabelOrientation(Qt::Vertical);
mX->setLineStyle(QwtPlotMarker::VLine);
mX->setLinePen(QPen(Qt::black, 0, Qt::DashDotLine));
mX->setXValue(2.0 * M_PI);
mX->attach(ui->qwtPlot);
}
void Widget::resizeEvent( QResizeEvent *event )
{
[b]QwtPlot::resizeEvent(event);[/b]
#ifdef Q_WS_X11
updateGradient(ui->qwtPlot );
#endif
}
void Widget::updateGradient( QwtPlot *plot )
{
QPalette pal = palette();
const QColor buttonColor = pal.color( QPalette::Button );
#ifdef Q_WS_X11
// Qt 4.7.1: QGradient::StretchToDeviceMode is buggy on X11
QLinearGradient gradient( rect().topLeft(), rect().bottomLeft() );
gradient.setColorAt( 0.0, Qt::white );
gradient.setColorAt( 0.7, buttonColor );
gradient.setColorAt( 1.0, buttonColor );
#else
QLinearGradient gradient( 0, 0, 0, 1 );
gradient.setCoordinateMode( QGradient::StretchToDeviceMode );
gradient.setColorAt( 0.0, Qt::white );
gradient.setColorAt( 0.7, buttonColor );
gradient.setColorAt( 1.0, buttonColor );
#endif
pal.setBrush( QPalette::Window, gradient );
plot->setPalette( pal );
}
Widget::~Widget()
{
delete ui;
}
Kod: Zaznacz cały
/home/zawisza/src/ploter-build-desktop/../ploter/widget.cpp:117: błąd:cannot call member function ‘virtual void QwtPlot::resizeEvent(QResizeEvent*)’ without object
Kod: Zaznacz cały
//ui->qwtPlot->resizeEvent(event);
QwtPlot::resizeEvent(event);
// ui->qwtPlot->resize(event->size() );
W przypadku 1 jest
Kod: Zaznacz cały
/usr/local/qwt-6.0.0/include/qwt_plot.h:274: błąd:‘virtual void QwtPlot::resizeEvent(QResizeEvent*)’ is protected
i 3
Kod: Zaznacz cały
/home/zawisza/src/ploter-build-desktop/../ploter/widget.cpp:119: błąd:invalid use of incomplete type ‘struct QResizeEvent’
/usr/include/qt4/QtGui/qwidget.h:83: błąd:forward declaration of ‘struct QResizeEvent’