qmake
make release
mingw32-make release
qwt.prf
file from the original qwt.prf
. Since I use the static version of the library, the QwtBuild
variable QwtBuild
assigned an empty value. In addition, in the win32
section, the value of the QwtBase
variable QwtBase
changed to the path to the directory in which I have installed the library.QwtPlot
. Several curves can be associated with it - QwtPlotCurve
objects. Actually, that's all.QwtBeginner
class, which is a descendant of the QWidget
class.QwtPlot
drawing QwtPlot
: function graphs will display function graphs on derPlot
, and derivatives of them graphs on derPlot
.sinFunCurve
, cubFunCurve
) and their derivatives ( sinDerCurve
, cubDerCurve
).sinButton
and cubButton
buttons will turn on and off the display of the corresponding graphs, and sinToggled()
and cubToggled()
slots will be attached to the signals of which.class QwtBeginner : public QWidget<br>{<br> Q_OBJECT<br><br> public :<br> QwtBeginner(QWidget *parent = 0);<br><br> private :<br> QwtPlot *funPlot, *derPlot;<br> QwtPlotCurve *sinFunCurve, *sinDerCurve;<br> QwtPlotCurve *cubFunCurve, *cubDerCurve;<br> QPushButton *sinButton, *cubButton;<br><br> private slots:<br> void sinToggled( bool checked );<br> void cubToggled( bool checked );<br>};
QwtBeginner::QwtBeginner(QWidget *parent)<br> : QWidget(parent)<br>{
// Create plots <br> funPlot = new QwtPlot;<br> derPlot = new QwtPlot;<br><br> funPlot->setTitle( "Function" );<br> derPlot->setTitle( "Derivative" );
// Create curves and attach them to plots <br> QPen sinPen = QPen(Qt::red);<br> QPen cubPen = QPen(Qt::blue);
RenderAntialiased
), point to “feathers” ( setPen()
), and tie the curves to the corresponding drawing areas ( attach()
).sinFunCurve = new QwtPlotCurve;<br> sinFunCurve->setRenderHint(QwtPlotItem::RenderAntialiased);<br> sinFunCurve->setPen(sinPen);<br> sinFunCurve->attach(funPlot);<br><br> sinDerCurve = new QwtPlotCurve;<br> sinDerCurve->setRenderHint(QwtPlotItem::RenderAntialiased);<br> sinDerCurve->setPen(sinPen);<br> sinDerCurve->attach(derPlot);<br><br> cubFunCurve = new QwtPlotCurve;<br> cubFunCurve->setRenderHint(QwtPlotItem::RenderAntialiased);<br> cubFunCurve->setPen(cubPen);<br> cubFunCurve->attach(funPlot);<br><br> cubDerCurve = new QwtPlotCurve;<br> cubDerCurve->setRenderHint(QwtPlotItem::RenderAntialiased);<br> cubDerCurve->setPen(cubPen);<br> cubDerCurve->attach(derPlot);
// Set data <br> const int N = 20;<br> double x[N+1];<br> double sinFunData[N+1], sinDerData[N+1];<br> double cubFunData[N+1], cubDerData[N+1];<br> for ( int i = 0; i <= N; ++i)<br> {<br> const double pi = 4.0 * atan(1.0);<br> double L = 2;<br> double h = L / N;<br><br> x[i] = -L/2 + i * h;<br> sinFunData[i] = sin(x[i] * pi);<br> sinDerData[i] = cos(x[i] * pi) * pi;<br> cubFunData[i] = x[i] * x[i] * x[i];<br> cubDerData[i] = 3 * x[i] * x[i];<br> }
sinFunCurve->setData(x, sinFunData, N+1);<br> sinDerCurve->setData(x, sinDerData, N+1);<br> cubFunCurve->setData(x, cubFunData, N+1);<br> cubDerCurve->setData(x, cubDerData, N+1);
// Hide curves <br> sinFunCurve->setVisible( false );<br> sinDerCurve->setVisible( false );<br><br> cubFunCurve->setVisible( false );<br> cubDerCurve->setVisible( false );
// Create buttons <br> sinButton = new QPushButton( "Sinus" ),<br> cubButton = new QPushButton( "Cubic function" ),<br><br> sinButton->setCheckable( true );<br> cubButton->setCheckable( true );<br><br> // Connect signals <br> connect(sinButton, SIGNAL(toggled( bool )), this , SLOT(sinToggled( bool )));<br> connect(cubButton, SIGNAL(toggled( bool )), this , SLOT(cubToggled( bool )));
// Set layouts <br> QHBoxLayout *plotsLayout = new QHBoxLayout;<br> plotsLayout->setSpacing(10);<br> plotsLayout->addWidget(funPlot);<br> plotsLayout->addWidget(derPlot);<br><br> QHBoxLayout *buttonsLayout = new QHBoxLayout ;<br> buttonsLayout->addWidget(sinButton);<br> buttonsLayout->addWidget(cubButton);<br><br> QVBoxLayout *widgetLayout = new QVBoxLayout;<br> widgetLayout->addLayout(plotsLayout);<br> widgetLayout->addLayout(buttonsLayout);<br><br> setLayout(widgetLayout);<br> showMaximized();<br>}
void QwtBeginner::sinToggled( bool checked )<br>{<br> sinFunCurve->setVisible( checked );<br> sinDerCurve->setVisible( checked );<br> funPlot->replot();<br> derPlot->replot();<br>} <br><br> void QwtBeginner::cubToggled( bool checked )<br>{<br> cubFunCurve->setVisible( checked );<br> cubDerCurve->setVisible( checked );<br> funPlot->replot();<br> derPlot->replot();<br>}
setVisible()
), but also redraw the drawing areas ( replot()
).int main( int argc, char *argv[])<br>{<br> QApplication app(argc, argv);<br> QwtBeginner *wnd = new QwtBeginner;<br> wnd->show();<br> return app.exec();<br>} <br><br> * This source code was highlighted with Source Code Highlighter .
tar.bz2
and zip
are available for download from the official website. At the time of this writing, the latest version is 5.2.0.qwtconfig.pri
file.CONFIG += QwtDll
" is CONFIG += QwtDll
(for some reason I am not going to have a Windows DLL).CONFIG += QwtExamples
" is uncommented.INSTALLBASE
" is INSTALLBASE
.qmake qwt.pro
mingw32-make
mingw32-make install
qmake qwt.pro
make
sudo make install
examples/
source subdirectory contains 15 more examples, among which are examples/simple_plot
, which served as the basis for my program.Source: https://habr.com/ru/post/82614/
All Articles