Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Rotating widget
Forum Updated to NodeBB v4.3 + New Features

Rotating widget

Scheduled Pinned Locked Moved Unsolved General and Desktop
2 Posts 2 Posters 1.0k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • S Offline
    S Offline
    sashapont
    wrote on last edited by
    #1

    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;
    }
    
    1 Reply Last reply
    0
    • mrjjM Offline
      mrjjM Offline
      mrjj
      Lifetime Qt Champion
      wrote on last edited by mrjj
      #2

      @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 :)

      1 Reply Last reply
      1

      • Login

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • Users
      • Groups
      • Search
      • Get Qt Extensions
      • Unsolved