QGraphicsRotation rotator; rotator.setOrigin(QVector3D(item->mapToScene(itemOriginQPointF))); QGraphicsScale scaler; scaler.setOrigin(QVector3D(item->mapToScene(itemOriginQPointF))); qDebug()<<item->mapToScene(itemOriginQPointF); qreal angle = ............ rotator.setAngle( angle ); qDebug()<<angle; qreal scale = ........... scaler.setYScale( scale ); qDebug()<<scale; qDebug()<<rotator.origin()<<rotator.angle()<<scaler.origin()<<scaler.yScale();
QPointF(575,220)49.00280.754266QVector3D(575, 220, 0) -10.9972 QVector3D(575, 220, 0) 1
C++ (Qt)#include "widget.h"#include <QGraphicsView>#include <QGraphicsScene>#include <QGraphicsSimpleTextItem>#include <QVBoxLayout> Widget::Widget( QWidget *parent ) : QWidget( parent ), m_view( new QGraphicsView( this ) ){ QVBoxLayout *l = new QVBoxLayout; l->addWidget( m_view ); setLayout( l ); QGraphicsScene *scene = new QGraphicsScene( this ); m_view->setScene( scene ); QGraphicsSimpleTextItem *item0 = new QGraphicsSimpleTextItem( tr( "Test string" ) ); scene->addItem( item0 ); QGraphicsSimpleTextItem *item1 = new QGraphicsSimpleTextItem( tr( "Test string" ) ); item1->setPos( 0, 20 ); item1->setTransform( QTransform().scale( 2, 1 ).rotate( 45 ) ); scene->addItem( item1 );}
C++ (Qt) item1->setTransform( QTransform().rotate( 45 ).scale( 2, 1 ) );
item->setTransform(QTransform().translate(rotationCenter.x(),rotationCenter.y()). rotate(angle).scale(scaleX,scaleY).translate(-rotationCenter.x(),-rotationCenter.y()));