[EDIT] : hmn maybe I didn't say all of this correct (and coping just a fragments of bigger code is not a good thing) so this is simple new project with my problem...
mainwindow.h :
#ifndef MAINWINDOW_H
#define MAINWINDOW_H
#include <QMainWindow>
namespace Ui {
class MainWindow;
}
{
Q_OBJECT
public:
explicit MainWindow
(QWidget *parent
= 0);
~MainWindow();
private:
Ui::MainWindow *ui;
};
#endif // MAINWINDOW_H
#ifndef MAINWINDOW_H
#define MAINWINDOW_H
#include <QMainWindow>
namespace Ui {
class MainWindow;
}
class MainWindow : public QMainWindow
{
Q_OBJECT
public:
explicit MainWindow(QWidget *parent = 0);
~MainWindow();
private:
Ui::MainWindow *ui;
};
#endif // MAINWINDOW_H
To copy to clipboard, switch view to plain text mode
mainwindow.cpp
#include <qwt_plot_curve.h>
#include <qwt_plot.h>
#include <qapplication.h>
#include <qwt_symbol.h>
#include <qwt_math.h>
#include <qcolor.h>
#include <qlayout.h>
#include <qpainter.h>
#include "mainwindow.h"
#include "ui_mainwindow.h"
MainWindow
::MainWindow(QWidget *parent
) : ui(new Ui::MainWindow)
{
ui->setupUi(this);
double x[100];
double y[100];
for(int i=0;i<100;i++)
{
x[i] = i/20.0;
y[i] = 0;
}
// add curves
curve->setRawSamples(x, y, 100);
curve
->setPen
(QColor(Qt
::darkGreen));
curve->attach(myPlot);
this->setCentralWidget(myPlot);
myPlot->autoReplot();
myPlot->replot();
}
MainWindow::~MainWindow()
{
delete ui;
}
#include <qwt_plot_curve.h>
#include <qwt_plot.h>
#include <qapplication.h>
#include <qwt_symbol.h>
#include <qwt_math.h>
#include <qcolor.h>
#include <qlayout.h>
#include <qpainter.h>
#include "mainwindow.h"
#include "ui_mainwindow.h"
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
ui->setupUi(this);
double x[100];
double y[100];
for(int i=0;i<100;i++)
{
x[i] = i/20.0;
y[i] = 0;
}
QwtPlot *myPlot = new QwtPlot(this);
// add curves
QwtPlotCurve *curve = new QwtPlotCurve();
curve->setRawSamples(x, y, 100);
curve->setSymbol(new QwtSymbol(QwtSymbol::Cross, Qt::NoBrush,
QPen(Qt::black), QSize(5, 5) ) );
curve->setPen(QColor(Qt::darkGreen));
curve->setStyle(QwtPlotCurve::Lines);
curve->setCurveAttribute(QwtPlotCurve::Fitted);
curve->attach(myPlot);
this->setCentralWidget(myPlot);
myPlot->autoReplot();
myPlot->replot();
}
MainWindow::~MainWindow()
{
delete ui;
}
To copy to clipboard, switch view to plain text mode
main.cpp
#include <qwt_plot_curve.h>
#include <qwt_plot.h>
#include <QApplication>
#include <qwt_symbol.h>
#include <qwt_math.h>
#include <qcolor.h>
#include <QDebug>
#include <QPushButton>
#include <qlayout.h>
#include <qpainter.h>
#include "mainwindow.h"
int main(int argc, char *argv[])
{
/*
QWidget w;
double x[100];
double y[100];
for(int i=0;i<100;i++)
{
x[i] = i/20.0;
y[i] = sin(x[i]);
}
QHBoxLayout *layout = new QHBoxLayout(&w);
layout->setContentsMargins( 0, 0, 0, 0 );
QwtPlot *myPlot = new QwtPlot(&w);
myPlot->setMinimumSize(w.geometry().width()-20,w.geometry().height()-20);
myPlot->updateGeometry();
// add curves
QwtPlotCurve *curve = new QwtPlotCurve();
curve->setRawSamples(x, y, 100);
curve->setSymbol(new QwtSymbol(QwtSymbol::Cross, Qt::NoBrush,
QPen(Qt::black), QSize(5, 5) ) );
curve->setPen(QColor(Qt::darkGreen));
curve->setStyle(QwtPlotCurve::Lines);
curve->setCurveAttribute(QwtPlotCurve::Fitted);
curve->attach(myPlot);
layout->addWidget(myPlot);
w.update();
*/
MainWindow w;
w.show();
return a.exec();
}
#include <qwt_plot_curve.h>
#include <qwt_plot.h>
#include <QApplication>
#include <qwt_symbol.h>
#include <qwt_math.h>
#include <qcolor.h>
#include <QDebug>
#include <QPushButton>
#include <qlayout.h>
#include <qpainter.h>
#include "mainwindow.h"
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
/*
QWidget w;
double x[100];
double y[100];
for(int i=0;i<100;i++)
{
x[i] = i/20.0;
y[i] = sin(x[i]);
}
QHBoxLayout *layout = new QHBoxLayout(&w);
layout->setContentsMargins( 0, 0, 0, 0 );
QwtPlot *myPlot = new QwtPlot(&w);
myPlot->setMinimumSize(w.geometry().width()-20,w.geometry().height()-20);
myPlot->updateGeometry();
// add curves
QwtPlotCurve *curve = new QwtPlotCurve();
curve->setRawSamples(x, y, 100);
curve->setSymbol(new QwtSymbol(QwtSymbol::Cross, Qt::NoBrush,
QPen(Qt::black), QSize(5, 5) ) );
curve->setPen(QColor(Qt::darkGreen));
curve->setStyle(QwtPlotCurve::Lines);
curve->setCurveAttribute(QwtPlotCurve::Fitted);
curve->attach(myPlot);
layout->addWidget(myPlot);
w.update();
*/
MainWindow w;
w.show();
return a.exec();
}
To copy to clipboard, switch view to plain text mode
mainwindow.ui
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>MainWindow</class>
<widget class="QMainWindow" name="MainWindow">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>400</width>
<height>300</height>
</rect>
</property>
<property name="windowTitle">
<string>MainWindow</string>
</property>
<widget class="QWidget" name="centralWidget"/>
</widget>
<layoutdefault spacing="6" margin="11"/>
<resources/>
<connections/>
</ui>
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>MainWindow</class>
<widget class="QMainWindow" name="MainWindow">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>400</width>
<height>300</height>
</rect>
</property>
<property name="windowTitle">
<string>MainWindow</string>
</property>
<widget class="QWidget" name="centralWidget"/>
</widget>
<layoutdefault spacing="6" margin="11"/>
<resources/>
<connections/>
</ui>
To copy to clipboard, switch view to plain text mode
two outcomes (on screens you can see which part of main function was commented which not)
and second
the question is : why first outcome is like that ? it paints only first point where is the rest ?
Bookmarks