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.
  • 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