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 to save only the scene in graphics view. actual scene width and scene height.
Forum Updated to NodeBB v4.3 + New Features

How to save only the scene in graphics view. actual scene width and scene height.

Scheduled Pinned Locked Moved Solved General and Desktop
8 Posts 3 Posters 604 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
    #1

    @JonB @ChrisW67 @Bonnie

    I wrote this code ,

    11.JPG

            m_Scene99.update();
            QThread::msleep(500);
            ui->graphicsView_103->setScene(&m_Scene99);
            m_Barcode99 = new Code128Item();
            m_Barcode99->setWidth(200);
            m_Barcode99->setHeight(70);
            m_Barcode99->setPos(0,0);
            m_Scene99.addItem( m_Barcode99);
            m_Scene99.update();
            m_Barcode99->update();
            m_Barcode99->setText(ui->lineEdit_7->text());
            m_Barcode99->update();
            m_Scene99.update();
            ui->graphicsView_103->setScene(&m_Scene99);
            ui->graphicsView_103->update();
            QThread::msleep(500);
    
            QImage img(m_Scene99.width(),m_Scene99.height,QImage::Format_ARGB32_Premultiplied);
            QPainter p(&img);
            m_Scene99.render(&p);
            p.end();
            img.save("img1.png");
    

    In this case, I saved 10 Images in different scenes in different QGraphicsview , it is saved but another scene is placed on top of one scene,

    123.JPG

    why is this happenning , here is what going wrong,

    Thank you,

    1 Reply Last reply
    1
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi,

      Why all the sleep in your code ? It blocks the event loop.

      Also, why not print the images directly rather than going through a QGraphicsScene/View ?

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      Ramkumar MohanR 1 Reply Last reply
      0
      • SGaistS SGaist

        Hi,

        Why all the sleep in your code ? It blocks the event loop.

        Also, why not print the images directly rather than going through a QGraphicsScene/View ?

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

        @SGaist

        I don't know how to print images directly.

        JonBJ 1 Reply Last reply
        0
        • Ramkumar MohanR Ramkumar Mohan

          @SGaist

          I don't know how to print images directly.

          JonBJ Offline
          JonBJ Offline
          JonB
          wrote on last edited by
          #4

          @Ramkumar-Mohan
          Then you should look at QPrinter Class. https://stackoverflow.com/questions/68764447/qprinter-image-gets-cut-off-when-printing shows some sample code, adapt that to your case.

          Ramkumar MohanR 1 Reply Last reply
          0
          • JonBJ JonB

            @Ramkumar-Mohan
            Then you should look at QPrinter Class. https://stackoverflow.com/questions/68764447/qprinter-image-gets-cut-off-when-printing shows some sample code, adapt that to your case.

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

            @JonB

            Ok ,

            one more doubt,

            how to save only the scene in QGraphicsview ,

            Eample,

            233.JPG

            I have Highlighed in the empty space .

            I want to scene only the barcode in my first post and skip the empty space in it.

            (or)

            How to set Scene width and height ,
            No matter how big the barcode is generated, it should only be in the width i give.
            how can i do,,,

            Thanks,

            JonBJ 1 Reply Last reply
            0
            • Ramkumar MohanR Ramkumar Mohan

              @JonB

              Ok ,

              one more doubt,

              how to save only the scene in QGraphicsview ,

              Eample,

              233.JPG

              I have Highlighed in the empty space .

              I want to scene only the barcode in my first post and skip the empty space in it.

              (or)

              How to set Scene width and height ,
              No matter how big the barcode is generated, it should only be in the width i give.
              how can i do,,,

              Thanks,

              JonBJ Offline
              JonBJ Offline
              JonB
              wrote on last edited by
              #6

              @Ramkumar-Mohan
              Neither @SGaist nor I understand what/why you are doing with a graphics scene or view.

              You seem to have an image which can be printed directly. If the empty space is in the image already then I would guess you must either remove it from the image or only copy the desired area into the QPainter by using QPainter::setClipRect(), see https://doc.qt.io/qt-6/qpainter.html#clipping.

              Ramkumar MohanR 1 Reply Last reply
              0
              • JonBJ JonB

                @Ramkumar-Mohan
                Neither @SGaist nor I understand what/why you are doing with a graphics scene or view.

                You seem to have an image which can be printed directly. If the empty space is in the image already then I would guess you must either remove it from the image or only copy the desired area into the QPainter by using QPainter::setClipRect(), see https://doc.qt.io/qt-6/qpainter.html#clipping.

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

                @JonB

                I don't have image already, I generate barcode, as different scene in different graphicsview, I save the scene in it as image, for each barcode generated width is taken as different, one barcode size is small and another barcode is set in GrpahicsView.

                Small generated barcode is getting empty space, large generated barcode is not getting empty space, when I print them one by one. Measurements are variable print.

                IMG_20221129_161323.jpg

                JonBJ 1 Reply Last reply
                0
                • Ramkumar MohanR Ramkumar Mohan

                  @JonB

                  I don't have image already, I generate barcode, as different scene in different graphicsview, I save the scene in it as image, for each barcode generated width is taken as different, one barcode size is small and another barcode is set in GrpahicsView.

                  Small generated barcode is getting empty space, large generated barcode is not getting empty space, when I print them one by one. Measurements are variable print.

                  IMG_20221129_161323.jpg

                  JonBJ Offline
                  JonBJ Offline
                  JonB
                  wrote on last edited by
                  #8

                  @Ramkumar-Mohan said in How to save only the scene in graphics view. actual scene width and scene height.:

                  I don't have image already, I generate barcode, as different scene in different graphicsview, I save the scene in it as image

                  As said previously, we do not know why you are introducing scenes, views, or multiple ones of each. But in any case you say you generate an image to print, by whatever means. So the suggestions for setting the area you want printed so that it excludes some blank area I made in my previous post still pertain.

                  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