QT 5 translate, scale, rotate and shear for QGraphicsItem

本文介绍了在Qt 5环境中,如何使用QGraphicsItem进行图形操作,包括translate平移、scale缩放、rotate顺时针旋转以及shear扭曲。在学习《Foundations of Qt Development》时遇到QGraphicsItem缺少translate和shear方法,通过QGraphicsItemAnimation类找到了解决方案,该类提供了实现这些图形变换的功能。操作过程中,关键在于设置step值并调整以实现所需变化效果。
摘要由CSDN通过智能技术生成

在学习《Foundations of Qt Development》中的7-20. A shape containing two other shapes + 7.21 Transforming the five items 时涉及到这些图形操作:translate 平移,scale 缩放,rotate 顺时针转动,shear 扭曲
我的环境是:Qt Creator 2.8.1;Based on Qt 5.1.1 (GCC 4.6.1, 32 bit)
编码时发现QGraphicsItem没有translate、shear。
在帮助中搜索找到了另一个类:QGraphicsItemAnimation
它提供了许多有用的函数,其中就包括了

void QGraphicsItemAnimation::setTranslationAt(qreal step, qreal dx, qreal dy);
void QGraphicsItemAnimation::setShearAt(qreal step, qreal sh, qreal sv);

设定step的初值,调用图形变化函数,最后改变step value,使得变化函数发挥作用。需要注意的是step value数值范围在[0,1]。

#include <QApplication>
#include <QtWidgets>

QGraphicsItem *createItem(int x){
    /* QRectF(qreal x, qreal y, qreal width, qreal height) */
    QGraphicsRectItem *rect = 
  • 1
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值