Monday, February 7, 2011

Qt Analog Clock

Yesterday, I downloaded and studied the AnalogCLock example on the QT4 website. The first thing experimented with  was changing the color of the hands. That process taught me a bit about the QPainter class, that the function can have 3 parameters (RGB) or 4 (RGB ,alpha). This is something useful about classes. Then, I added another hand to represent the unit seconds. Of course, I had to get it moving. This I did using: painter.rotate( time.second()*6.0);.

During this process, I could not quite get it right, so I decided to print out some numbers. I read about the QTimer class and what it was outputting. The following command printed output to the console (being sure to #include <QtDebug> in the header):

qDebug() << "minute is:" << time.minute() ;

I found that QDevelop does not output anything until the running program closes. I ran the code at a terminal and the output was updated instantly. This is important because I want to understand the event driven nature of QT. Putting in a print statement like "This event has been called" helped me a great deal when I was learnign widgets in IDL.

I found another informational class, QMessageBox which, when used in the following statement, will pop up a window, at the console and from within Qdevelop. This is what I will use.

QMessageBox::information(this, tr("Status"),"Are you ready?");.

No comments:

Post a Comment