C++ (Qt)QPoint topleft( 0, 0 ); // top left picture offsetQPolygon pl( QRect( topleft, QSize( 30, 60 ) ), true );QMatrix m;m.rotate( 40 );pl = m.map( pl );
C++ (Qt)if( pl.containsPoint( event->pos() ) ) ....
C++ (Qt)inline bool PtInsideRotatedRect( const QRect & R, float angle_radians, QPoint pt ){ pt -= R.center(); qreal x = cos(angle_radians), y = sin(angle_radians); qreal px = pt.x(), py = pt.y(); qreal rel_x = px * x + py * y; qreal rel_y = px * y - py * x; qreal w2 = R.width() * 0.5f; qreal h2 = R.height() * 0.5f; return fabs(rel_x) <= w2 && fabs(rel_y) <= h2;}
C++ (Qt)#include "UiMainWindow.h"#include "ui_UiMainWindow.h" UiMainWindow::UiMainWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::UiMainWindow){ ui->setupUi(this); // здесь картинку можно выбрать по вкусу _img = QImage(QString::fromUtf8("e:\\Картинки\\1\\Daddy-Bliss.jpg")).scaled(60, 80); _angle = 0; connect(&_timer, SIGNAL(timeout()), this, SLOT(timerTick())); _timer.setInterval(10); _timer.start();} UiMainWindow::~UiMainWindow(){ delete ui;} void UiMainWindow::timerTick(){ repaint(); _angle++; if (_angle >= 360) _angle = 0;} void UiMainWindow::paintEvent(QPaintEvent *event){ QPainter p(this); QPoint c = rect().center(); QMatrix wm1; wm1.translate( -c.x(), -c.y() ); QMatrix wm2; wm2.rotate( -_angle ); QMatrix wm3; wm3.translate( c.x(), c.y() ); p.save(); p.setMatrix( wm1 * wm2 * wm3 ); p.drawImage(c-_img.rect().center(), _img); p.restore(); p.drawLine(0,c.y(),width(),c.y()); p.drawLine(c.x(),0,c.x(),height());}