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. How can i move the QWidget in QGraphicsView?
Qt 6.11 is out! See what's new in the release blog

How can i move the QWidget in QGraphicsView?

Scheduled Pinned Locked Moved Solved General and Desktop
6 Posts 2 Posters 1.3k Views
  • 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
    seokwon
    wrote on last edited by seokwon
    #1
    MainWindow::MainWindow(QWidget *parent) :
        QMainWindow(parent),
        ui(new Ui::MainWindow)
    {
        ui->setupUi(this);
        ui->graphicsView->setGeometry(0,0,geometry().width(),geometry().height());
        scene = new QGraphicsScene(0, 0, geometry().width(), geometry().height(), this);
    
        ui->graphicsView->setScene(scene);
    
        QPushButton *button =new QPushButton(NULL);
        button->setText("move it");
        scene->addWidget(button);
       }
    

    Hello, This is my code.
    I want to move the QPushButton or kind of QWidget in QGraphicsView for example QListWidet, QTableWidget etc.
    So, How can i move QWidget?

    jsulmJ 1 Reply Last reply
    0
    • S seokwon
      MainWindow::MainWindow(QWidget *parent) :
          QMainWindow(parent),
          ui(new Ui::MainWindow)
      {
          ui->setupUi(this);
          ui->graphicsView->setGeometry(0,0,geometry().width(),geometry().height());
          scene = new QGraphicsScene(0, 0, geometry().width(), geometry().height(), this);
      
          ui->graphicsView->setScene(scene);
      
          QPushButton *button =new QPushButton(NULL);
          button->setText("move it");
          scene->addWidget(button);
         }
      

      Hello, This is my code.
      I want to move the QPushButton or kind of QWidget in QGraphicsView for example QListWidet, QTableWidget etc.
      So, How can i move QWidget?

      jsulmJ Offline
      jsulmJ Offline
      jsulm
      Lifetime Qt Champion
      wrote on last edited by
      #2

      @seokwon http://doc.qt.io/qt-5/qwidget.html#setGeometry-1

      https://forum.qt.io/topic/113070/qt-code-of-conduct

      S 1 Reply Last reply
      1
      • jsulmJ jsulm

        @seokwon http://doc.qt.io/qt-5/qwidget.html#setGeometry-1

        S Offline
        S Offline
        seokwon
        wrote on last edited by seokwon
        #3

        @jsulm
        Thanks. But I want to move like a QGraphicsItem::SetFlag(QGraphicsItem::ItemIsMovable).
        Can i not move in the same way as QGraphicsItem?
        Can i move using mouse click then move?

        jsulmJ 1 Reply Last reply
        0
        • S seokwon

          @jsulm
          Thanks. But I want to move like a QGraphicsItem::SetFlag(QGraphicsItem::ItemIsMovable).
          Can i not move in the same way as QGraphicsItem?
          Can i move using mouse click then move?

          jsulmJ Offline
          jsulmJ Offline
          jsulm
          Lifetime Qt Champion
          wrote on last edited by
          #4

          @seokwon See http://doc.qt.io/qt-5/qgraphicsproxywidget.html

          https://forum.qt.io/topic/113070/qt-code-of-conduct

          S 1 Reply Last reply
          1
          • jsulmJ jsulm

            @seokwon See http://doc.qt.io/qt-5/qgraphicsproxywidget.html

            S Offline
            S Offline
            seokwon
            wrote on last edited by seokwon
            #5

            @jsulm
            I already try it. but It is not work ..
            This is my code.

               ui->graphicsView->setGeometry(0,0,geometry().width(),geometry().height());
                scene = new QGraphicsScene(0, 0, geometry().width(), geometry().height(), this);
            
                ui->graphicsView->setScene(scene);
            
                QPushButton *button =new QPushButton(NULL);
                QGraphicsProxyWidget *proxyItem = new QGraphicsProxyWidget;
                proxyItem->setWidget(button);
                proxyItem->setFlag(QGraphicsWidget::ItemIsMovable);
                scene->addItem(proxyItem);
            
            

            Can you tell me what is wrong?

            jsulmJ 1 Reply Last reply
            0
            • S seokwon

              @jsulm
              I already try it. but It is not work ..
              This is my code.

                 ui->graphicsView->setGeometry(0,0,geometry().width(),geometry().height());
                  scene = new QGraphicsScene(0, 0, geometry().width(), geometry().height(), this);
              
                  ui->graphicsView->setScene(scene);
              
                  QPushButton *button =new QPushButton(NULL);
                  QGraphicsProxyWidget *proxyItem = new QGraphicsProxyWidget;
                  proxyItem->setWidget(button);
                  proxyItem->setFlag(QGraphicsWidget::ItemIsMovable);
                  scene->addItem(proxyItem);
              
              

              Can you tell me what is wrong?

              jsulmJ Offline
              jsulmJ Offline
              jsulm
              Lifetime Qt Champion
              wrote on last edited by
              #6

              @seokwon Take a look at https://stackoverflow.com/questions/26990502/why-qgraphicsitemitemismovable-has-no-effect

              https://forum.qt.io/topic/113070/qt-code-of-conduct

              1 Reply Last reply
              0

              • Login

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