Here's a short demo using qwt that writes a .png image. On screen, the vertical axis is okay, but the .png image shows the letters failed to rotate 90 deg.
/* ------ myplot.hpp ------ */
#ifndef myplot_hpp
#define myplot_hpp
#include <qwt/qwt.h>
#include <qwt/qwt_plot.h>
{
Q_OBJECT
public:
MyPlot();
void setup_details_1();
};
#endif
/* ------ myplot.hpp ------ */
#ifndef myplot_hpp
#define myplot_hpp
#include <qwt/qwt.h>
#include <qwt/qwt_plot.h>
class MyPlot : public QwtPlot
{
Q_OBJECT
public:
MyPlot();
void setup_details_1();
};
#endif
To copy to clipboard, switch view to plain text mode
/* ------ myplot.cpp ------ */
#include "myplot.hpp"
MyPlot::MyPlot()
{
}
void MyPlot::setup_details_1()
{
setTitle("Dizziness of Millisecond Pulsars");
setAxisTitle
(QwtPlot::xBottom,
"whizzyness");
setAxisTitle
(QwtPlot::yLeft,
"wooziness");
}
/* ------ myplot.cpp ------ */
#include "myplot.hpp"
MyPlot::MyPlot()
: QwtPlot()
{
}
void MyPlot::setup_details_1()
{
setTitle("Dizziness of Millisecond Pulsars");
setAxisTitle(QwtPlot::xBottom, "whizzyness");
setAxisTitle(QwtPlot::yLeft, "wooziness");
}
To copy to clipboard, switch view to plain text mode
/* ------ qwtdemo2.hpp ------ */
#include <QtGui>
#include <QWidget>
#include "myplot.hpp"
class MyMainWindow
: public QWidget{
Q_OBJECT
public:
~MyMainWindow();
void createcontents();
public slots:
void printmyplot();
private:
public:
MyPlot* myplot;
};
/* ------ qwtdemo2.hpp ------ */
#include <QtGui>
#include <QWidget>
#include "myplot.hpp"
class MyMainWindow : public QWidget
{
Q_OBJECT
public:
MyMainWindow(QWidget *parent=0);
~MyMainWindow();
void createcontents();
public slots:
void printmyplot();
private:
QPushButton *print_button;
QPushButton *quit_button;
public:
MyPlot* myplot;
};
To copy to clipboard, switch view to plain text mode
/* ------ qwtdemo2.cpp ------ */
/*
simple demo using qwt
"print" button writes a .png file
see if vert scale text has unturned letters
*/
#include <QtGui>
#include <QWidget>
#include <stdio.h>
#include <unistd.h>
#include "myplot.hpp"
#include "qwtdemo2.hpp"
MyMainWindow::~MyMainWindow() {}
MyMainWindow
::MyMainWindow(QWidget *parent
) : QWidget(parent
), print_button
(0), quit_button
(0), myplot
(0) {
resize(500,500);
setWindowTitle("QWT Simple Demo #1");
}
void MyMainWindow::createcontents()
{
myplot = new MyPlot;
bottomrow->addWidget(print_button);
bottomrow->addWidget(quit_button);
mainlayout->addWidget(myplot);
mainlayout->addLayout(bottomrow); // use setLayout()?
setLayout(mainlayout);
connect(quit_button, SIGNAL(clicked()),
this, SLOT(close()));
connect(print_button, SIGNAL(clicked()),
this, SLOT(printmyplot()));
}
void MyMainWindow::printmyplot()
{
QRect rect
(0,
0,
500,
500);
myplot->print(&painter, rect);
printf("aobut to save ");
image.save("000.png", "PNG", 1);
printf("return from ::printmyplot \n");
}
int main(int nargs, char** args)
{
MyMainWindow *mainwindow = new MyMainWindow;
mainwindow->createcontents();
mainwindow->myplot->setup_details_1();
mainwindow->show();
return app.exec();
}
/* ------ qwtdemo2.cpp ------ */
/*
simple demo using qwt
"print" button writes a .png file
see if vert scale text has unturned letters
*/
#include <QtGui>
#include <QWidget>
#include <stdio.h>
#include <unistd.h>
#include "myplot.hpp"
#include "qwtdemo2.hpp"
MyMainWindow::~MyMainWindow() {}
MyMainWindow::MyMainWindow(QWidget *parent)
: QWidget(parent), print_button(0), quit_button(0), myplot(0)
{
resize(500,500);
setWindowTitle("QWT Simple Demo #1");
}
void MyMainWindow::createcontents()
{
print_button = new QPushButton("print", this);
quit_button = new QPushButton("quit", this);
myplot = new MyPlot;
QHBoxLayout *bottomrow = new QHBoxLayout;
bottomrow->addWidget(print_button);
bottomrow->addWidget(quit_button);
QVBoxLayout *mainlayout = new QVBoxLayout;
mainlayout->addWidget(myplot);
mainlayout->addLayout(bottomrow); // use setLayout()?
setLayout(mainlayout);
connect(quit_button, SIGNAL(clicked()),
this, SLOT(close()));
connect(print_button, SIGNAL(clicked()),
this, SLOT(printmyplot()));
}
void MyMainWindow::printmyplot()
{
QImage image(500,500, QImage::Format_ARGB32);
QPainter painter(&image);
QRect rect(0,0, 500,500);
myplot->print(&painter, rect);
printf("aobut to save ");
image.save("000.png", "PNG", 1);
printf("return from ::printmyplot \n");
}
int main(int nargs, char** args)
{
QApplication app(nargs, args);
MyMainWindow *mainwindow = new MyMainWindow;
mainwindow->createcontents();
mainwindow->myplot->setup_details_1();
mainwindow->show();
return app.exec();
}
To copy to clipboard, switch view to plain text mode
# .pro file to build qwtdemo2
TEMPLATE = app
TARGET =
DEPENDPATH += .
INCLUDEPATH += .
INCLUDEPATH += $(QWT)/include
LIBS += -lqwt
HEADERS += myplot.hpp qwtdemo2.hpp
SOURCES += myplot.cpp qwtdemo2.cpp
# .pro file to build qwtdemo2
TEMPLATE = app
TARGET =
DEPENDPATH += .
INCLUDEPATH += .
INCLUDEPATH += $(QWT)/include
LIBS += -lqwt
HEADERS += myplot.hpp qwtdemo2.hpp
SOURCES += myplot.cpp qwtdemo2.cpp
To copy to clipboard, switch view to plain text mode
Bookmarks