Qt/QWT/Plot
From ProgrammingExamples
main.cpp
#include <QApplication> #include "form.h" int main(int argc, char *argv[]) { QApplication app(argc, argv); MyForm form; form.show(); return app.exec(); }
form.h
#ifndef BUTTONFORM_H #define BUTTONFORM_H #include "ui_form.h" class MyForm : public QWidget, private Ui::Form { Q_OBJECT public: MyForm(QWidget *parent = 0); public slots: }; #endif
form.cpp
#include "form.h" #include <qwt_plot.h> #include <qwt_plot_curve.h> #include <qwt_series_data.h> MyForm::MyForm(QWidget *parent) : QWidget(parent) { setupUi(this); QwtPlot *myPlot = new QwtPlot(this); QwtPlotCurve *curve1 = new QwtPlotCurve("Curve 1"); QwtPointSeriesData myData; QVector<QPointF> samples; samples.push_back(QPointF(1.0,1.0)); samples.push_back(QPointF(2.0,2.0)); samples.push_back(QPointF(3.0,3.0)); samples.push_back(QPointF(4.0,5.0)); myData.setSamples(samples); curve1->setData(&myData); curve1->attach(myPlot); myPlot->replot(); }
form.ui
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>Form</class>
<widget class="QWidget" name="Form">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>400</width>
<height>300</height>
</rect>
</property>
<property name="windowTitle">
<string>My Program</string>
</property>
<widget class="QLabel" name="label">
<property name="geometry">
<rect>
<x>120</x>
<y>220</y>
<width>141</width>
<height>18</height>
</rect>
</property>
<property name="text">
<string>Before click</string>
</property>
</widget>
<widget class="QDialogButtonBox" name="buttonBox">
<property name="geometry">
<rect>
<x>110</x>
<y>120</y>
<width>176</width>
<height>27</height>
</rect>
</property>
<property name="standardButtons">
<set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set>
</property>
</widget>
</widget>
<resources/>
<connections/>
</ui>CMakeLists.txt
cmake_minimum_required(VERSION 2.6) PROJECT(QWT) FIND_PACKAGE(Qt4 REQUIRED) INCLUDE(${QT_USE_FILE}) QT4_WRAP_UI(UISrcs form.ui) QT4_WRAP_CPP(MOCSrcs form.h) include_directories(${include_directories} ${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_CURRENT_BINARY_DIR} /home/doriad/src/qwt-6.0/src) link_directories(/home/doriad/src/qwt-6.0/lib) ADD_EXECUTABLE(QWT main.cpp form.cpp ${MOCSrcs} ${UISrcs}) TARGET_LINK_LIBRARIES(QWT ${QT_LIBRARIES} qwt)