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. Want to have a common method to save the PNG of QMainWindow ,QGraphicsView. Qwidget
Qt 6.11 is out! See what's new in the release blog

Want to have a common method to save the PNG of QMainWindow ,QGraphicsView. Qwidget

Scheduled Pinned Locked Moved Unsolved General and Desktop
17 Posts 4 Posters 5.6k Views 3 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.
  • m.sueM Offline
    m.sueM Offline
    m.sue
    wrote on last edited by
    #2

    You get the screenshot in form of a QImage. This you can save in multple formats (incl. PNG) with the save function: http://doc.qt.io/qt-5/qimage.html#reading-and-writing-image-files

    -Michael.

    1 Reply Last reply
    0
    • Q Offline
      Q Offline
      Qt Enthusiast
      wrote on last edited by
      #3

      my Question is how to get QImage from object of

      1. QMainWindow
      2. QWidget
      3. QGraphicsView
      m.sueM 1 Reply Last reply
      0
      • Q Qt Enthusiast

        my Question is how to get QImage from object of

        1. QMainWindow
        2. QWidget
        3. QGraphicsView
        m.sueM Offline
        m.sueM Offline
        m.sue
        wrote on last edited by
        #4

        @Qt-Enthusiast

        You can use one of the render functions of QWidget: http://doc.qt.io/qt-5/qwidget.html#render There you can use a QImage as QPaintDevice argument.

        -Michael.

        1 Reply Last reply
        0
        • Q Offline
          Q Offline
          Qt Enthusiast
          wrote on last edited by
          #5

          this is not working for QGraphicsView version 4.3.3

          QPixmap * pixmap = new QPixMap(this->size())
          this render(pixmap)
          pixmap->save(fileName)

          does not work for QGraphicsView in 4.3.3 . Could you please comment

          m.sueM 1 Reply Last reply
          0
          • Q Qt Enthusiast

            this is not working for QGraphicsView version 4.3.3

            QPixmap * pixmap = new QPixMap(this->size())
            this render(pixmap)
            pixmap->save(fileName)

            does not work for QGraphicsView in 4.3.3 . Could you please comment

            m.sueM Offline
            m.sueM Offline
            m.sue
            wrote on last edited by
            #6

            @Qt-Enthusiast

            What does not work? What does it do that is not correct?

            1 Reply Last reply
            0
            • Q Offline
              Q Offline
              Qt Enthusiast
              wrote on last edited by
              #7

              I am getting compilation error

              class myView: plublic QGraphicsView {

              }

              no matching function call for myView::render(QPixMap* &)

              m.sueM 1 Reply Last reply
              0
              • Q Qt Enthusiast

                I am getting compilation error

                class myView: plublic QGraphicsView {

                }

                no matching function call for myView::render(QPixMap* &)

                m.sueM Offline
                m.sueM Offline
                m.sue
                wrote on last edited by
                #8

                @Qt-Enthusiast

                Maybe a typo: QPixMap -> QPixmap

                1 Reply Last reply
                0
                • Q Offline
                  Q Offline
                  Qt Enthusiast
                  wrote on last edited by
                  #9

                  no even if fix typo it is issue

                  Could you please try ant your end where I can common method to save snapshot of QMainWindow ,QWidget amd QGraphicsView and a sample sample code will be helpful

                  1 Reply Last reply
                  0
                  • Q Offline
                    Q Offline
                    Qt Enthusiast
                    wrote on last edited by
                    #10

                    QPixmap *px = new QPixmap(this->size());
                    this->render(pixmap);
                    pixmap->save(file) not working for QGraphicsview but working for QMainWindow and QWidget

                    for QGraphicsView , render not found and signature should be QGraphicsView::render(QPainter

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

                      Hi,

                      Do you have "#include <QPixmap>" in your .cpp file ?

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

                      1 Reply Last reply
                      0
                      • Q Offline
                        Q Offline
                        Qt Enthusiast
                        wrote on last edited by
                        #12

                        Yes it is included

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

                          Can you show the complete code ?

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

                          1 Reply Last reply
                          0
                          • Q Qt Enthusiast

                            QPixmap *px = new QPixmap(this->size());
                            this->render(pixmap);
                            pixmap->save(file) not working for QGraphicsview but working for QMainWindow and QWidget

                            for QGraphicsView , render not found and signature should be QGraphicsView::render(QPainter

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

                            @Qt-Enthusiast said in Want to have a common method to save the PNG of QMainWindow ,QGraphicsView. Qwidget:

                            QPixmap *px = new QPixmap(this->size());
                            this->render(pixmap);
                            pixmap->save(file) not working for QGraphicsview but working for QMainWindow and QWidget

                            for QGraphicsView , render not found and signature should be QGraphicsView::render(QPainter

                            I think this is because the render method is overloaded in QGraphicsView, but only for QPainter*, not for QPaintDevice*.

                            You can easily solve that problem by creating your own painter like so:

                            {
                               QPainter painter;
                               QPixmap pixmap(sizeX,sizeY);
                               painter.begin(&pixmap);
                               this->render(&painter);
                               painter.end();
                               pixmap.save(file);
                            }
                            1 Reply Last reply
                            2
                            • SGaistS Offline
                              SGaistS Offline
                              SGaist
                              Lifetime Qt Champion
                              wrote on last edited by SGaist
                              #15

                              @Asperamanca the render method using QPaintDevice is inherited from QWidget so it looks like there's something else at play.

                              render is not virtual so it will be hidden by the new version of the derived class.

                              [edit: fixed comment SGaist]

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

                              A 1 Reply Last reply
                              0
                              • SGaistS SGaist

                                @Asperamanca the render method using QPaintDevice is inherited from QWidget so it looks like there's something else at play.

                                render is not virtual so it will be hidden by the new version of the derived class.

                                [edit: fixed comment SGaist]

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

                                @SGaist said in Want to have a common method to save the PNG of QMainWindow ,QGraphicsView. Qwidget:

                                @Asperamanca the render method using QPaintDevice is inherited from QWidget so it looks like there's something else at play.

                                When you have two overloads of a method in the base class, and reimplement one of them in a derived class, you will (by default) no longer be able to call the other one. Unless you allow it through the 'using' keyword. I don't see QGraphicsView doing that.

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

                                  @Asperamanca absolutely correct, I've forgotten that render wasn't a virtual method.

                                  Interested in AI ? www.idiap.ch
                                  Please read the Qt Code of Conduct - 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