Damir
Damir

Reputation: 56189

Rotate whole qwidget by angle

I am creating simple tetris in wt and I inherited widget to create piece ( I put four pieces in game, four different classes ). I draw on paint event in every piece. How to rotate widget ? Ican draw rotated image in painEvent function but I would rather rotate whole widget. Is this pissible in qt ?

Upvotes: 5

Views: 10535

Answers (1)

ramzes2
ramzes2

Reputation: 762

You can't easily rotate any widget in Qt. But you can add your widget to QGraphicsScene, rotate it and show on QGraphicsView. Here is a short example how to do it:

QGraphicsScene *scene = new QGraphicsScene(this);
QPushButton *button = new QPushButton();
button->setText("My cool button");

QGraphicsProxyWidget *w = scene->addWidget(button);
w->setPos(50, 50);
w->setRotation(45);
ui->graphicsView->setScene(scene);

enter image description here

Alternatively you can rewrite all on QML. In QML you can rotate almost anything.

Upvotes: 9

Related Questions