QGraphicItem实现中心旋转
来源:互联网 发布:mac磁盘管理工具 编辑:程序博客网 时间:2024/05/16 15:17
QGraphicItem实现中心旋转
一、解决思路
1)确定旋转中心坐标:centerPos;
2)在mousePressEvent(QMouseEvent *e)中e->pos()获得按下时的坐标:pressPos
3)mouseMoveEvent(QMouseEvent *e)中e->pos()获得当前坐标:movePos;
4)centerPos、pressPos、movePos三点确定旋转角度:rotateAngle;
5)QTransform transform;
transform.rotate(rotateAngle, Qt::ZAix); //沿着Z轴旋转角度rotateAngle
this->setTransform(transform);
6)Done。
获取旋转中心:
QPointF centerPos=Item->boundingRect().center();
设置旋转中心:
void QGraphicsItem::setTransformOriginPoint(qreal x, qreal y)
设置旋转角度:
void QGraphicsItem::setRotation(qreal angle)
三、难点
1.角度确定
2.判断是顺时针还是逆时针
思路:在平面上作向量OA、OB,OA叉乘OB为正,则是逆时针,为负为顺时针.
过程:
记向量OA为(dx1, dy1) = (x2-x1, y2-y1)向量OB为(dx2, dy2) = (x3-x1, y3-y1)叉积为:
即:
dx1 * dy2 - dy1 * dx2
3.鼠标根据在Item的位置进行形状的改变
思路:通过判断鼠标在Item的位置进行形状的替换,可设置四种形状:
RotationLeftUp,RotationLeftDown,RotationRightUp,RotationRightDown.旋转的鼠标样式可以自定义。
QCursor *myCursor= newe QCursor(QPixmap(":/image/rotation.png"));
一、解决思路
1)确定旋转中心坐标:centerPos;
2)在mousePressEvent(QMouseEvent *e)中e->pos()获得按下时的坐标:pressPos
3)mouseMoveEvent(QMouseEvent *e)中e->pos()获得当前坐标:movePos;
4)centerPos、pressPos、movePos三点确定旋转角度:rotateAngle;
5)QTransform transform;
transform.rotate(rotateAngle, Qt::ZAix); //沿着Z轴旋转角度rotateAngle
this->setTransform(transform);
6)Done。
二、 示意图
获取旋转中心:
QPointF centerPos=Item->boundingRect().center();
设置旋转中心:
void QGraphicsItem::setTransformOriginPoint(qreal x, qreal y)
设置旋转角度:
void QGraphicsItem::setRotation(qreal angle)
三、难点
1.角度确定
采用余弦定理:
2.判断是顺时针还是逆时针
思路:在平面上作向量OA、OB,OA叉乘OB为正,则是逆时针,为负为顺时针.
过程:
记向量OA为(dx1, dy1) = (x2-x1, y2-y1)向量OB为(dx2, dy2) = (x3-x1, y3-y1)叉积为:
即:
dx1 * dy2 - dy1 * dx2
3.鼠标根据在Item的位置进行形状的改变
思路:通过判断鼠标在Item的位置进行形状的替换,可设置四种形状:
RotationLeftUp,RotationLeftDown,RotationRightUp,RotationRightDown.旋转的鼠标样式可以自定义。
QCursor *myCursor= newe QCursor(QPixmap(":/image/rotation.png"));
setCursor(*myCursor);
http://blog.csdn.net/u013207966/article/details/51892289
阅读全文
0 0
- QGraphicItem实现中心旋转
- QGraphicItem实现中心旋转
- Rotate实现围绕中心旋转动画
- [Android] 代码实现按钮/图片自旋转(中心旋转)
- 元素中心旋转在CSS3和IE滤镜中的实现
- 元素中心旋转在CSS3和IE滤镜中的实现
- 元素绕中心旋转
- android,中心旋转
- opengl 旋转中心理解
- Unity更改模型中心和旋转中心
- 由旋转矩阵求旋转中心
- Android 仪表盘 图片 中心 旋转
- android 围绕中心旋转动
- android 围绕中心旋转动画
- android 围绕中心旋转动画
- android 围绕中心旋转动画
- 绕中心旋转的圆环
- java 图片绕中心旋转
- java异常—检查异常(checked exception)和未检查异常(unchecked exception)
- java 重载、重写、构造函数详解
- 集成学习算法总结----Boosting和Bagging
- Context理解
- 关于组件先后顺序的问题
- QGraphicItem实现中心旋转
- nodejs-新建项目及Error:Connot find module 'jade'或者‘ejs’ .......错误的解决方法
- Meta http-equiv属性详解(转)
- 夜神模拟器使用后Android studio不能再使用源生模拟器
- S
- 51Nod 1085 背包问题(01)
- 为springmvc设置servelet、拦截器(interceptor)、监听器(listener)、过滤器(filter),类型转换器
- Objective-C中获取视频指定帧的方法
- 欢迎使用CSDN-markdown编辑器