2009-12-09 56 views

回答

1

我會承擔這樣的事情,對於QTimer和繪畫之間的相互作用:

// Periodically paints a sinusoid on itself. 
class SinPainter : public QWidget 
{ 
    Q_OBJECT 
public: 
    SinPainter(QWidget *parent_p = NULL) : 
     QWidget(parent_p), 
     m_timer_p(new QTimer(this)), 
     m_t(0.0) 
    { 
     // When the timer goes off, run our function to change the t value. 
     connect(m_timer_p, SIGNAL(timeout()), SLOT(ChangeT())); 
     // Start the timer to go off every TIMER_INTERVAL milliseconds 
     m_timer_p->start(TIMER_INTERVAL); 
    } 

    // ... 

protected slots: 
    void ChangeT() 
    { 
     // Change m_t to the new value. 
     m_t += T_INCREMENT; 
     // Calling update schedules a repaint event, assuming one hasn't 
     // already been scheduled. 
     update(); 
    } 

protected: 
    void paintEvent(QPaintEvent *e_p) 
    { 
     QPainter painter(this); 
     // Use painter and m_t to draw your current sinusoid according 
     // to your function. 
    } 

private: 
    QTimer *m_timer_p; 
    double m_t; // <-- Or whatever variable type it needs to be. 
}; 
+0

非常好,謝謝你。 – Hannibal 2009-12-09 20:35:56