Qt学习例子12——Movablesimley
2011-04-08 13:16
369 查看
Movablesimley 工程在前面的基础上使节点可以移动
程序效果图:(笑脸可以移动的)
依据此图而作:
#include <QtGui/QApplication>
#include <QGraphicsView>
#include <QGraphicsScene>
#include <QGraphicsEllipseItem>
QGraphicsItem *addSmiley() {
QPen thickPen(Qt::black);
thickPen.setWidth(2);
// add face
QGraphicsEllipseItem *face = new QGraphicsEllipseItem(QRect(-50, -50, 100, 100));
face->setPen(Qt::NoPen);
face->setBrush(Qt::yellow);
// add eyes
QGraphicsEllipseItem *leftEye = new QGraphicsEllipseItem(QRectF(-6, -12, 12, 24), face);
leftEye->setPen(thickPen);
leftEye->setBrush(Qt::white);
leftEye->setPos(-15, -25);
QGraphicsEllipseItem *rightEye = new QGraphicsEllipseItem(QRectF(-6, -12, 12, 24), face);
rightEye->setPen(thickPen);
rightEye->setBrush(Qt::white);
rightEye->setPos(15, -25);
// add smile
QPainterPath smileArc;
QRect rect(-33, -15, 66, 50);
smileArc.arcMoveTo(rect, 0);
smileArc.arcTo(rect, 0, -180);
QGraphicsPathItem *smile = new QGraphicsPathItem(smileArc, face);
smile->setPen(thickPen);
return face;
}
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
QGraphicsView w;
QGraphicsScene scene;
w.setScene(&scene);
QGraphicsItem *smiley = addSmiley();
scene.addItem(smiley);
// enter your code here
smiley->setFlag(QGraphicsItem::ItemIsMovable,true);
w.setRenderHint(QPainter::Antialiasing);
w.show();
w.resize(600,400);
return a.exec();
}
程序效果图:(笑脸可以移动的)
相关文章推荐
- Qt学习例子1——HelloWorld
- Qt学习例子15——objectitem
- Qt学习之旅---3.文件处理,小例子文本编辑器
- Qt学习例子2——CalculatorInterface
- qt fortuneserver 例子学习 ( 给客户端发送消息)
- Qt学习例子15——objectitem
- Qt多线程学习-用例子来理解多线程
- Qt下的OpenGL 编程(12)阶段学习总结
- Qt学习例子3——test
- Qt下的OpenGL 编程(12)阶段学习总结
- Qt学习之路_12(简易数据管理系统)
- Qt学习例子4——Test2_1
- Qt学习例子5——calculatorwidget
- QT学习之二:Qt命令模式下建立编译的第一个例子
- Qt学习例子6——customtype
- Qt 学习之路 2(12):菜单栏、工具栏和状态栏
- Qt学习例子7——fileaccess
- Qt学习(12)
- Qt多线程学习-用例子来理解多线程(转)
- Qt下的OpenGL 编程(12)阶段学习总结