Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Rotate whole qwidget by angle

Tags:

qt

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 ?

like image 461
Damir Avatar asked Feb 05 '23 16:02

Damir


1 Answers

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.

like image 161
ramzes2 Avatar answered Feb 12 '23 01:02

ramzes2