Results 1 to 4 of 4

Thread: QwtPlot + UI problem

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #3
    Join Date
    Apr 2012
    Posts
    2
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: QwtPlot + UI problem

    [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 :

    Qt Code:
    1. #ifndef MAINWINDOW_H
    2. #define MAINWINDOW_H
    3.  
    4. #include <QMainWindow>
    5.  
    6. namespace Ui {
    7. class MainWindow;
    8. }
    9.  
    10. class MainWindow : public QMainWindow
    11. {
    12. Q_OBJECT
    13.  
    14. public:
    15. explicit MainWindow(QWidget *parent = 0);
    16. ~MainWindow();
    17.  
    18. private:
    19. Ui::MainWindow *ui;
    20. };
    21.  
    22. #endif // MAINWINDOW_H
    To copy to clipboard, switch view to plain text mode 

    mainwindow.cpp
    Qt Code:
    1. #include <qwt_plot_curve.h>
    2. #include <qwt_plot.h>
    3. #include <qapplication.h>
    4. #include <qwt_symbol.h>
    5. #include <qwt_math.h>
    6. #include <qcolor.h>
    7. #include <qlayout.h>
    8. #include <qpainter.h>
    9. #include "mainwindow.h"
    10. #include "ui_mainwindow.h"
    11.  
    12. MainWindow::MainWindow(QWidget *parent) :
    13. QMainWindow(parent),
    14. ui(new Ui::MainWindow)
    15. {
    16. ui->setupUi(this);
    17. double x[100];
    18. double y[100];
    19.  
    20. for(int i=0;i<100;i++)
    21. {
    22. x[i] = i/20.0;
    23. y[i] = 0;
    24. }
    25. QwtPlot *myPlot = new QwtPlot(this);
    26. // add curves
    27. QwtPlotCurve *curve = new QwtPlotCurve();
    28. curve->setRawSamples(x, y, 100);
    29. curve->setSymbol(new QwtSymbol(QwtSymbol::Cross, Qt::NoBrush,
    30. QPen(Qt::black), QSize(5, 5) ) );
    31. curve->setPen(QColor(Qt::darkGreen));
    32. curve->setStyle(QwtPlotCurve::Lines);
    33. curve->setCurveAttribute(QwtPlotCurve::Fitted);
    34. curve->attach(myPlot);
    35. this->setCentralWidget(myPlot);
    36. myPlot->autoReplot();
    37. myPlot->replot();
    38. }
    39.  
    40. MainWindow::~MainWindow()
    41. {
    42. delete ui;
    43. }
    To copy to clipboard, switch view to plain text mode 


    main.cpp
    Qt Code:
    1. #include <qwt_plot_curve.h>
    2. #include <qwt_plot.h>
    3. #include <QApplication>
    4. #include <qwt_symbol.h>
    5. #include <qwt_math.h>
    6. #include <qcolor.h>
    7. #include <QDebug>
    8. #include <QPushButton>
    9. #include <qlayout.h>
    10. #include <qpainter.h>
    11. #include "mainwindow.h"
    12.  
    13. int main(int argc, char *argv[])
    14. {
    15. QApplication a(argc, argv);
    16. /*
    17.   QWidget w;
    18.   double x[100];
    19.   double y[100];
    20.  
    21.   for(int i=0;i<100;i++)
    22.   {
    23.   x[i] = i/20.0;
    24.   y[i] = sin(x[i]);
    25.   }
    26.   QHBoxLayout *layout = new QHBoxLayout(&w);
    27.   layout->setContentsMargins( 0, 0, 0, 0 );
    28.   QwtPlot *myPlot = new QwtPlot(&w);
    29.   myPlot->setMinimumSize(w.geometry().width()-20,w.geometry().height()-20);
    30.   myPlot->updateGeometry();
    31.   // add curves
    32.   QwtPlotCurve *curve = new QwtPlotCurve();
    33.   curve->setRawSamples(x, y, 100);
    34.   curve->setSymbol(new QwtSymbol(QwtSymbol::Cross, Qt::NoBrush,
    35.   QPen(Qt::black), QSize(5, 5) ) );
    36.   curve->setPen(QColor(Qt::darkGreen));
    37.   curve->setStyle(QwtPlotCurve::Lines);
    38.   curve->setCurveAttribute(QwtPlotCurve::Fitted);
    39.   curve->attach(myPlot);
    40.   layout->addWidget(myPlot);
    41.   w.update();
    42. */
    43. MainWindow w;
    44. w.show();
    45.  
    46. return a.exec();
    47. }
    To copy to clipboard, switch view to plain text mode 


    mainwindow.ui
    Qt Code:
    1. <?xml version="1.0" encoding="UTF-8"?>
    2. <ui version="4.0">
    3. <class>MainWindow</class>
    4. <widget class="QMainWindow" name="MainWindow">
    5. <property name="geometry">
    6. <rect>
    7. <x>0</x>
    8. <y>0</y>
    9. <width>400</width>
    10. <height>300</height>
    11. </rect>
    12. </property>
    13. <property name="windowTitle">
    14. <string>MainWindow</string>
    15. </property>
    16. <widget class="QWidget" name="centralWidget"/>
    17. </widget>
    18. <layoutdefault spacing="6" margin="11"/>
    19. <resources/>
    20. <connections/>
    21. </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 ?
    Last edited by petromp; 5th April 2012 at 11:51.

Similar Threads

  1. Replies: 0
    Last Post: 17th February 2012, 08:41
  2. QWTPLOT problem
    By umulingu in forum Qwt
    Replies: 5
    Last Post: 25th August 2009, 16:34
  3. Replies: 6
    Last Post: 14th May 2009, 12:02
  4. Problem regarding QWTPLOT
    By sudheer168 in forum Qwt
    Replies: 1
    Last Post: 6th January 2009, 14:18
  5. Problem with QwtPlot
    By sudheer168 in forum Qwt
    Replies: 1
    Last Post: 11th September 2008, 09:04

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Qt is a trademark of The Qt Company.