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 ?
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);
Alternatively you can rewrite all on QML. In QML you can rotate almost anything.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With