Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. [SOLVED] Removing paint event and Repaint!
Forum Updated to NodeBB v4.3 + New Features

[SOLVED] Removing paint event and Repaint!

Scheduled Pinned Locked Moved General and Desktop
2 Posts 1 Posters 2.2k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Offline
    M Offline
    MrNoway
    wrote on last edited by
    #1

    Hi, guys, it's me again,
    first of all I really wanna thank you all for helping me, I appreciate it.

    here comes my next problem.
    I fnally succeeded drawing a perfect sinus with dots.
    i gave my sinus even a little random look using rand();

    http://s1.directupload.net/images/121206/iiug9xcy.jpg
    or
    http://img713.imageshack.us/img713/3548/drawpots.jpg

    so I what I need is, after reaching the horizontal dot a certain value,
    I want to delete the painted line/curve/dots and painting again.

    here is how it looks so far.

    It would also work, just take the drawn dots and change their x and y values,
    but I dont know how to do this.

    HEADER

    @#include <qwidget>
    #include <math.h>

    class Lines : public QWidget
    {
    Q_OBJECT
    QTimer *timer1;
    QVector<QPoint> m_points;
    QVector<QPoint> m_2points;
    double vertical;
    double vertical2;
    double horizontal;
    double counter;
    double counter2;
    double random_a;
    double random_b;

    public:
    Lines(QWidget *parent = 0);

    protected:
    void paintEvent(QPaintEvent *event);
    void drawLines(QPainter *qp);

    public slots:
    void call_repaint();

    };
    @

    MAIN
    @#include <qpainter>
    #include "prototype.h"
    #include <qpainter.h>
    #include <qtimer.h>
    #include <Windows.h>
    #include <math.h>
    #include <iostream>
    #include <iomanip>
    using namespace std;

    Lines::Lines(QWidget *parent) : QWidget(parent)
    {
    counter = 0;
    counter2 = 1;
    vertical=0;
    vertical2=0;
    horizontal=0;
    random_a=0.05;

      timer1=new QTimer(this);
    timer1->setInterval(10);
    timer1->start();
    

    connect(timer1, SIGNAL(timeout()), this, SLOT(call_repaint()));

    }

    void Lines::paintEvent(QPaintEvent *e)
    {
    Q_UNUSED(e);
    QPainter ppp(this);
    drawLines(&ppp);
    }

    void Lines::call_repaint(){
    srand(time(NULL));
    horizontal++;
    double xxx;
    double yyy;

    xxx=sin(counter);
    yyy=sin(counter2);

    counter=counter+0.05;
    counter2=counter2+random_a;

    vertical = vertical + (xxx2);
    vertical2 = vertical2 + (yyy
    1);

    // !!!! Drawing
    m_points.append(QPoint(2+horizontal,50+vertical));
    m_2points.append(QPoint(2+horizontal,195+vertical2));
    repaint();}

    // !!!!! Changing Sinus
    if ( horizontal == 150 )
    {random_a = rand ()10 +1;random_a = random_a / 80; }

    // !!!!! Changing Sinus
    if ( horizontal == 400 )
    {srand(time(NULL)); random_a = rand () +1; random_a = random_a / 80; }
    // !!!!! After Reaching a certain value I want to draw again from the beginning
    if ( horizontal == 800){horizontal = 0;}

    void Lines::drawLines(QPainter *qp)
    {

    QPen pen(Qt::black, 2, Qt::SolidLine);
    qp->setPen(pen);

    QPoint pt;
    foreach(pt, m_points)
    {
        qp->drawPoint(pt);
    }
    

    foreach(pt, m_2points)
    {
    qp->drawPoint(pt);
    }}@

    I posted the whole code, so maybe someone can learn from it.
    Some parts were little tricky with the sinus.

    1 Reply Last reply
    0
    • M Offline
      M Offline
      MrNoway
      wrote on last edited by
      #2

      wow, I am pretty sure, this is the wrong way to code this

      but you can simply create a new

      @QVector<QPoint> m_3points;@

      and then
      @
      if ( horizontal == 800){
      m_2points = m_3points;
      }@

      then it just disappears, cool

      1 Reply Last reply
      0

      • Login

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • Users
      • Groups
      • Search
      • Get Qt Extensions
      • Unsolved