今天开始接触了qt,刚开始为了搭环境,找qt create找了好久,网上不怎么好找,找了一个晚上才找到的,先把资源分享一下给大家。
QTSDK分享 http://pan.baidu.com/s/1cJ3jPW (傻瓜式操作,直接安装,有点大,选择自己需要的系统版本)
各版本的qt http://download.qt.io/archive/qt/4.8/4.8.6/
还有,本人英语不是太好,有些帮助手册看不太懂,也找了一个中文资料。
http://www.kuqin.com/qtdocument/index.html
以上的分享都是网上找的,希望大家在搭建环境的时候能少费一些功夫吧。
在环境搭建好之后,我开始学着做个小项目,看看能不能把界面搭起来,也是找了很多资料,查了很多视频,个人觉得Qt小神童的教程很不错,简单易懂,很适合初学者。以下是我仿照写的一个小项目,一个时钟。
#ifndef CLOCK_H
#define CLOCK_H
#include <QtGui/QMainWindow>
#include <qpainter>
#include <QPoint>
#include <QTime>
#include <QTimer>
static QPoint sed[4] = {QPoint(0, -70), QPoint(2,0), QPoint(0,10), QPoint(-2,0)};
static QPoint min[4] = {QPoint(0, -60), QPoint(4,0), QPoint(0,12), QPoint(-4,0)};
static QPoint hour[4] = {QPoint(0, -50), QPoint(6,0), QPoint(0,13), QPoint(-6,0)};
class Clock : public QMainWindow
{
Q_OBJECT
public:
Clock(QWidget *parent = 0);
~Clock();
protected:
void paintEvent(QPaintEvent *);
};
#endif // CLOCK_H
#include "clock.h"
Clock::Clock(QWidget *parent)
: QMainWindow(parent)
{
QTimer *timer = new QTimer(this);
timer->start(1000);
connect(timer, SIGNAL(timeout()), this, SLOT(update()));
resize(200, 200);
}
Clock::~Clock()
{
}
void Clock::paintEvent(QPaintEvent *)
{
QPainter paint(this);
QTime time = QTime::currentTime();
paint.translate(100,100);
//paint.drawLine(0,0,100,100);
paint.setRenderHint(QPainter::Antialiasing);
paint.setPen(QPen(Qt::black,0.5,Qt::DashLine));
paint.setBrush(QBrush(Qt::white,Qt::SolidPattern));//设置画刷形式
paint.drawEllipse(-100,-100,200,200);
paint.setBrush(Qt::red);
paint.setPen(Qt::red);
paint.save();
paint.rotate(6.0*time.second());
paint.drawConvexPolygon(sed, 4);
paint.restore();
paint.setBrush(Qt::blue);
paint.setPen(Qt::blue);
paint.save();
paint.rotate(6.0*time.minute()+time.second()/60.0);
paint.drawConvexPolygon(min, 4);
paint.restore();
paint.setBrush(Qt::black);
paint.setPen(Qt::black);
paint.save();
paint.rotate(30.0*time.hour()+time.minute()/60.0);
paint.drawConvexPolygon(hour, 4);
paint.restore();
int i;
for(i = 0; i < 12; i++)
{
paint.rotate(30);
paint.drawLine(0,-98,0,-88);
}
for(i = 0; i < 60; i++)
{
paint.rotate(6);
paint.drawLine(0,-98,0,-95);
}
}
#include <QtGui/QApplication>
#include "clock.h"
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
Clock w;
w.show();
return a.exec();
}