Unsolved Rotating widget
-
I try to rotate widget^ but it is not work^ what I am doing wrong^ and how i can fix that?
#include "mainwindow.h" #include "ui_mainwindow.h" #include <QApplication> #include <QLineEdit> #include <QGraphicsScene> #include <QGraphicsProxyWidget> #include <QGraphicsView> MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::MainWindow) { ui->setupUi(this); // QPushButton *bouton = new QPushButton("Mon bouton entre en scène !"); QGraphicsScene scene; QGraphicsProxyWidget *proxy = new QGraphicsProxyWidget(); proxy->setWidget(ui->pushButton); scene.addItem(proxy); scene.setSceneRect(-150, -150, 300, 300); QGraphicsView view(&scene); view.show(); proxy->setRotation(45); } MainWindow::~MainWindow() { delete ui; }
-
@sashapont said:
Hi
I assume, you see absolutely nothing?You define your scene as
QGraphicsScene scene;
which means its DELETED as soon as mainwindow constructor ends.same with your view
QGraphicsView view(&scene);also gone as soon as constructor ends. Which is before the window is even shown.
you should use new and pointer so they can live longer, or you put them in the class.
or both :)