I do not know which version of the Thunderbolt, there is a "download speed histogram" of the small interface, I prefer (but the latest version of the Thunderbolt is not), so decided to cottage one. Of course, this cottage can not download files, hehe.
Ideas:
1: Paint the background of the interface black
2: Generate a random number every 0.1 seconds and add them to a container
3: Overload the PaintEvent function, starting from the right side of the interface and sequentially drawing the elements in the container in reverse order (each data is a bar)
:
Code:
[CPP]View Plaincopyprint?
- #include <QtGui>
- #include <QtCore>
- Class Barchart: Public qwidget
- {
- Q_object
- Private
- qlist<int> m_list; //Store the points recorded in the history
- Qsize m_size; //size of the current drawing window
- Qtimer M_timer; //timer, sends a signal every 0.1 seconds, simulates receiving data
- Protected
- void PaintEvent (Qpaintevent *event);
- void Resizeevent (Qresizeevent *event);
- Public
- Barchart (Qwidget *parent = 0);
- ~barchart () {}
- Public Slots:
- void Adddataslot ();
- };
- Barchart::barchart (Qwidget *parent)
- : Qwidget (parent)
- {
- //define Timers
- Qsrand (Qdatetime::currentdatetime (). Tomsecssinceepoch ());
- Connect (&m_timer, SIGNAL (timeout ()), this , SLOT (Adddataslot ()));
- M_timer.start (100);
- }
- void Barchart::p aintevent (qpaintevent *event)
- {
- const int WIDTH = 2;
- qpainter painter (this);
- //Set Background to black
- Painter.setbrush (Qt::black);
- Painter.drawrect ( -2,-2, M_size.width () +4, M_size.height () +4);
- Painter.setpen (Qpen (Qt::green, WIDTH));
- int TX, CX, CY1, Cy2;
- tx = 0;
- Cy1 = M_size.height ();
- //Draw a vertical line of each section
- qlist<Int>::iterator iter = M_list.end ();
- While (iter! = M_list.begin ())
- {
- Cy2 = Cy1-(* (--iter) *m_size.height ()/1000);
- CX = M_size.width ()-TX;
- Painter.drawline (CX, Cy1, CX, cy2);
- TX + = WIDTH;
- }
- }
- void Barchart::resizeevent (Qresizeevent *event)
- {
- M_size = Event->size ();
- Update ();
- }
- void Barchart::adddataslot ()
- {
- //Add a 0-999 of data
- int temp = Qrand ()% 1000;
- M_list.push_back (temp);
- //If the data is too long, throw away the previous part
- if (m_list.size () > M_size.width ())
- M_list.pop_front ();
- Update ();
- }
- #include "Main.moc"
- int main (int argc, char **argv)
- {
- Qapplication app (argc, argv);
- Barchart *bar = new Barchart;
- Bar->show ();
- return app.exec ();
- }
http://blog.csdn.net/small_qch/article/details/7585758
QT: "Download speed histogram" simulation implementation--thinking really good, can use their brains, even I have inspired (this idea seems to be universal)