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. Multiple scenes in one QGraphicview
Forum Updated to NodeBB v4.3 + New Features

Multiple scenes in one QGraphicview

Scheduled Pinned Locked Moved Solved General and Desktop
14 Posts 3 Posters 1.8k Views 2 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.
  • Ramkumar MohanR Offline
    Ramkumar MohanR Offline
    Ramkumar Mohan
    wrote on last edited by Ramkumar Mohan
    #1

    This is my code ,

        int check = 4 ;
        for(int i=0;i<check;i++)
        {
            ui->graphicsView->setFixedSize(215 , 110);
            ui->graphicsView->setSceneRect(0,0,215,110);
            ui->graphicsView->setScene(&m_Scene);
            m_Code->setWidth(35);
            m_Code->setHeight(70);
            m_Code->setPos(15,15);
            m_Scene.addItem( m_Code );
            m_Scene.update();
            m_Code->update();
            m_Code->setText(ui->lineEdit_7->text());
            m_Code->update();
            m_Scene.update();
        }
    

    In this m_Code means that every time the loop comes, the new shapes will be displayed in the Same QGraphicsView one by one.

    I don't know how to do that,
    How to display Multiple scenes in a single QGraphicsView.

    JonBJ 1 Reply Last reply
    0
    • Ramkumar MohanR Ramkumar Mohan

      This is my code ,

          int check = 4 ;
          for(int i=0;i<check;i++)
          {
              ui->graphicsView->setFixedSize(215 , 110);
              ui->graphicsView->setSceneRect(0,0,215,110);
              ui->graphicsView->setScene(&m_Scene);
              m_Code->setWidth(35);
              m_Code->setHeight(70);
              m_Code->setPos(15,15);
              m_Scene.addItem( m_Code );
              m_Scene.update();
              m_Code->update();
              m_Code->setText(ui->lineEdit_7->text());
              m_Code->update();
              m_Scene.update();
          }
      

      In this m_Code means that every time the loop comes, the new shapes will be displayed in the Same QGraphicsView one by one.

      I don't know how to do that,
      How to display Multiple scenes in a single QGraphicsView.

      JonBJ Online
      JonBJ Online
      JonB
      wrote on last edited by JonB
      #2

      @Ramkumar-Mohan said in Multiple scenes in one QGraphicview:

      How to display Multiple scenes in a single QGraphicsView.

      You can't, and wouldn't want to! A QGraphicsView is a view onto (an area of) one QGraphicsScene, via QGraphicsView::setScene(QGraphicsScene *scene). You can't have it view more than one scene! OTOH, it's fine to have multiple QGraphicsViews onto a single QGraphicsScene, e.g. to view different areas.

      I don't know why you think you would want multiple QGraphicsScenes nor what the code you show is trying to achieve.

      Ramkumar MohanR JonBJ 2 Replies Last reply
      2
      • JonBJ JonB

        @Ramkumar-Mohan said in Multiple scenes in one QGraphicview:

        How to display Multiple scenes in a single QGraphicsView.

        You can't, and wouldn't want to! A QGraphicsView is a view onto (an area of) one QGraphicsScene, via QGraphicsView::setScene(QGraphicsScene *scene). You can't have it view more than one scene! OTOH, it's fine to have multiple QGraphicsViews onto a single QGraphicsScene, e.g. to view different areas.

        I don't know why you think you would want multiple QGraphicsScenes nor what the code you show is trying to achieve.

        Ramkumar MohanR Offline
        Ramkumar MohanR Offline
        Ramkumar Mohan
        wrote on last edited by
        #3

        @JonB Ok,

        Header File ,

        MainWindow.h

        class MainWindow : public QMainWindow
        {
        Q_OBJECT

        QGraphicsScene m_Scene;
        QGraphicsScene m_Scene1;
        

        }

        CPP File ,

        MainWindow.CPP
        int check =2 ;
        for(int i=0 ; i<check ;i++)
        {
        if(i==0)

                         {
                             ui->graphicsView->setFixedSize(420 , 580);
                             ui->graphicsView->setSceneRect(50,0,215,110);
                             QThread::msleep(500);
                             ui->graphicsView->setScene(&m_Scene);
                             m_Code= new Code128Item();
                             m_Code->setWidth(35);
                             m_Code->setHeight(70);
                             m_Code->setPos(50,0);
                             m_Scene.addItem( m_Code);
                             m_Scene.update();
                             m_Code->update();
                             m_Code->setText(Data);
                             m_Code->update();
                             m_Scene.update();
                             ui->graphicsView->setScene(&m_Scene);
                             ui->graphicsView->update();
                         } 
        

        else if(i==1)
        {

                    ui->graphicsView->setFixedSize(420 , 580);
                    ui->graphicsView->setSceneRect(200,0,215,110);
                    QThread::msleep(500);
        
                    ui->graphicsView->setScene(&m_Scene1);
                    m_Code->setWidth(35);
                    m_Code->setHeight(70);
                    m_Code->setPos(200,0);
                    m_Scene1.addItem(m_Code);
                    m_Scene1.update();
                    m_Code->update();
                    m_Code->setText("Data1");
                    m_Code->update();
                    m_Scene1.update();
                    ui->graphicsView->setScene(&m_Scene1);
                    ui->graphicsView->update();          
        

        }
        }

        I wrote This code ,

        In this the text named data should be placed at (0,0) position, similarly the text named Data1 should be placed at (200,0) position. I don't know what is wrong with this code.

        A 1 Reply Last reply
        0
        • Ramkumar MohanR Ramkumar Mohan

          @JonB Ok,

          Header File ,

          MainWindow.h

          class MainWindow : public QMainWindow
          {
          Q_OBJECT

          QGraphicsScene m_Scene;
          QGraphicsScene m_Scene1;
          

          }

          CPP File ,

          MainWindow.CPP
          int check =2 ;
          for(int i=0 ; i<check ;i++)
          {
          if(i==0)

                           {
                               ui->graphicsView->setFixedSize(420 , 580);
                               ui->graphicsView->setSceneRect(50,0,215,110);
                               QThread::msleep(500);
                               ui->graphicsView->setScene(&m_Scene);
                               m_Code= new Code128Item();
                               m_Code->setWidth(35);
                               m_Code->setHeight(70);
                               m_Code->setPos(50,0);
                               m_Scene.addItem( m_Code);
                               m_Scene.update();
                               m_Code->update();
                               m_Code->setText(Data);
                               m_Code->update();
                               m_Scene.update();
                               ui->graphicsView->setScene(&m_Scene);
                               ui->graphicsView->update();
                           } 
          

          else if(i==1)
          {

                      ui->graphicsView->setFixedSize(420 , 580);
                      ui->graphicsView->setSceneRect(200,0,215,110);
                      QThread::msleep(500);
          
                      ui->graphicsView->setScene(&m_Scene1);
                      m_Code->setWidth(35);
                      m_Code->setHeight(70);
                      m_Code->setPos(200,0);
                      m_Scene1.addItem(m_Code);
                      m_Scene1.update();
                      m_Code->update();
                      m_Code->setText("Data1");
                      m_Code->update();
                      m_Scene1.update();
                      ui->graphicsView->setScene(&m_Scene1);
                      ui->graphicsView->update();          
          

          }
          }

          I wrote This code ,

          In this the text named data should be placed at (0,0) position, similarly the text named Data1 should be placed at (200,0) position. I don't know what is wrong with this code.

          A Offline
          A Offline
          Asperamanca
          wrote on last edited by
          #4

          @Ramkumar-Mohan
          I don't see what "m_Code" is, but why not simply add two texts to one scene?

          Ramkumar MohanR 2 Replies Last reply
          1
          • A Asperamanca

            @Ramkumar-Mohan
            I don't see what "m_Code" is, but why not simply add two texts to one scene?

            Ramkumar MohanR Offline
            Ramkumar MohanR Offline
            Ramkumar Mohan
            wrote on last edited by
            #5

            @Asperamanca
            m_Code Means,

            MainWindow.h

            class MainWindow : public QMainWindow
            {
            Q_OBJECT

            QGraphicsScene m_Scene;
            QGraphicsScene m_Scene1;
            Code128Item * m_Code;
            

            }

            A 1 Reply Last reply
            0
            • Ramkumar MohanR Ramkumar Mohan

              @Asperamanca
              m_Code Means,

              MainWindow.h

              class MainWindow : public QMainWindow
              {
              Q_OBJECT

              QGraphicsScene m_Scene;
              QGraphicsScene m_Scene1;
              Code128Item * m_Code;
              

              }

              A Offline
              A Offline
              Asperamanca
              wrote on last edited by
              #6

              @Ramkumar-Mohan
              So just create 2 items like m_Code, instead of 2 scenes

              1 Reply Last reply
              0
              • JonBJ JonB

                @Ramkumar-Mohan said in Multiple scenes in one QGraphicview:

                How to display Multiple scenes in a single QGraphicsView.

                You can't, and wouldn't want to! A QGraphicsView is a view onto (an area of) one QGraphicsScene, via QGraphicsView::setScene(QGraphicsScene *scene). You can't have it view more than one scene! OTOH, it's fine to have multiple QGraphicsViews onto a single QGraphicsScene, e.g. to view different areas.

                I don't know why you think you would want multiple QGraphicsScenes nor what the code you show is trying to achieve.

                JonBJ Online
                JonBJ Online
                JonB
                wrote on last edited by
                #7

                @Ramkumar-Mohan

                @JonB said in Multiple scenes in one QGraphicview:

                I don't know why you think you would want multiple QGraphicsScenes

                Like @Asperamanca says too.

                Ramkumar MohanR 2 Replies Last reply
                0
                • JonBJ JonB

                  @Ramkumar-Mohan

                  @JonB said in Multiple scenes in one QGraphicview:

                  I don't know why you think you would want multiple QGraphicsScenes

                  Like @Asperamanca says too.

                  Ramkumar MohanR Offline
                  Ramkumar MohanR Offline
                  Ramkumar Mohan
                  wrote on last edited by
                  #8

                  @JonB

                  Now , working fine , Thank You

                  1 Reply Last reply
                  0
                  • JonBJ JonB

                    @Ramkumar-Mohan

                    @JonB said in Multiple scenes in one QGraphicview:

                    I don't know why you think you would want multiple QGraphicsScenes

                    Like @Asperamanca says too.

                    Ramkumar MohanR Offline
                    Ramkumar MohanR Offline
                    Ramkumar Mohan
                    wrote on last edited by
                    #9

                    @JonB

                    Hi, one more doubt ,

                    Can multiple QGraphviews be printed to the printer one by one?

                    JonBJ 1 Reply Last reply
                    0
                    • Ramkumar MohanR Ramkumar Mohan

                      @JonB

                      Hi, one more doubt ,

                      Can multiple QGraphviews be printed to the printer one by one?

                      JonBJ Online
                      JonBJ Online
                      JonB
                      wrote on last edited by JonB
                      #10

                      @Ramkumar-Mohan
                      I imagine so, why not? Certainly assuming you can print one QGraphicsView you can print many.

                      Ramkumar MohanR 1 Reply Last reply
                      0
                      • JonBJ JonB

                        @Ramkumar-Mohan
                        I imagine so, why not? Certainly assuming you can print one QGraphicsView you can print many.

                        Ramkumar MohanR Offline
                        Ramkumar MohanR Offline
                        Ramkumar Mohan
                        wrote on last edited by
                        #11

                        @JonB

                        I am a beginner in qt and I don't really understand its concept.

                        1 Reply Last reply
                        0
                        • A Asperamanca

                          @Ramkumar-Mohan
                          I don't see what "m_Code" is, but why not simply add two texts to one scene?

                          Ramkumar MohanR Offline
                          Ramkumar MohanR Offline
                          Ramkumar Mohan
                          wrote on last edited by
                          #12

                          @Asperamanca @JonB

                          Capture.JPG

                          QGraphicsView Items should be set in this way ....

                          how to set the graph scale...

                          Thank you.

                          A 1 Reply Last reply
                          0
                          • Ramkumar MohanR Ramkumar Mohan

                            @Asperamanca @JonB

                            Capture.JPG

                            QGraphicsView Items should be set in this way ....

                            how to set the graph scale...

                            Thank you.

                            A Offline
                            A Offline
                            Asperamanca
                            wrote on last edited by
                            #13

                            @Ramkumar-Mohan
                            Not sure what the question here is. You can transform individual items (scale, rotate, shear), and you can do the same for the whole GraphicsView.

                            As for printing: You can grab a QPixmap or QImage of each GraphicsView and print it, for example.

                            Ramkumar MohanR 1 Reply Last reply
                            1
                            • A Asperamanca

                              @Ramkumar-Mohan
                              Not sure what the question here is. You can transform individual items (scale, rotate, shear), and you can do the same for the whole GraphicsView.

                              As for printing: You can grab a QPixmap or QImage of each GraphicsView and print it, for example.

                              Ramkumar MohanR Offline
                              Ramkumar MohanR Offline
                              Ramkumar Mohan
                              wrote on last edited by
                              #14
                              This post is deleted!
                              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