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. Catch QFrame to QPixmap
Qt 6.11 is out! See what's new in the release blog

Catch QFrame to QPixmap

Scheduled Pinned Locked Moved Solved General and Desktop
16 Posts 5 Posters 5.0k 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.
  • mrjjM mrjj

    Hi
    You assign painter to pixmap AFTER you grab.
    Also where do you run this code ?
    Should not be in constructor as it might not have right size.

    void ManualControlForm::screendump() {
    
      QPixmap pix; // might need to set size
      QPainter painter(&pix);
      painter.setRenderHint(QPainter::Antialiasing);
      frame->render(&painter);
      painter.end();
      pix.save("/tmp/ramdisk/test2.png");
    
    }
    
    G Offline
    G Offline
    Gourmet
    wrote on last edited by Gourmet
    #7

    @mrjj
    If render to QPainter then waterfall of messages

    (null):0 ((null)): QWidget::repaint: Recursive repaint detected

    appears in app window and then app fails.

    I run this code inside paintEvent() as I said before. Looks like render to QPainter calls paintEvent() - therefore recursion appears. But I need get content of frame inside paintEvent()... I have to think more...

    mrjjM 1 Reply Last reply
    0
    • G Gourmet

      @mrjj
      If render to QPainter then waterfall of messages

      (null):0 ((null)): QWidget::repaint: Recursive repaint detected

      appears in app window and then app fails.

      I run this code inside paintEvent() as I said before. Looks like render to QPainter calls paintEvent() - therefore recursion appears. But I need get content of frame inside paintEvent()... I have to think more...

      mrjjM Offline
      mrjjM Offline
      mrjj
      Lifetime Qt Champion
      wrote on last edited by
      #8

      @Gourmet
      Can you show the whole function ?
      Do you ask the QFrame to render() inside its own paintEvent ??

      G 1 Reply Last reply
      0
      • mrjjM mrjj

        @Gourmet
        Can you show the whole function ?
        Do you ask the QFrame to render() inside its own paintEvent ??

        G Offline
        G Offline
        Gourmet
        wrote on last edited by
        #9

        @mrjj
        No.
        Yes. I already said this before.

        mrjjM 1 Reply Last reply
        0
        • G Gourmet

          @mrjj
          No.
          Yes. I already said this before.

          mrjjM Offline
          mrjjM Offline
          mrjj
          Lifetime Qt Champion
          wrote on last edited by
          #10

          @Gourmet
          Well you are still not showing full code.
          I done this many times and normally have zero issue with it.
          (for screen shot features)
          So you are clearly doing something odd, wrong or unexpected.
          But you only said
          "piece of code from paintEvent() of this class"
          and show nothing more relevant information.

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

            Hi,

            That's the main problem, you're asking the widget to paint itself when it's already painting itself, hence the error you get.

            Do that somewhere else but not in the paintEvent of your QFrame.

            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
            1
            • mrjjM Offline
              mrjjM Offline
              mrjj
              Lifetime Qt Champion
              wrote on last edited by
              #12

              Ah, i missed the YES mean he called inside QFrame paint. :)
              That will lead to recursive behavior.
              Thanks @SGaist

              1 Reply Last reply
              0
              • G Offline
                G Offline
                Gourmet
                wrote on last edited by
                #13

                Yes, gotcha... just made QPixmap pm class-wide field and removed pm = grab(QRect(QPoint(0,0),size())); to another method before update() - and all is working. To be on safe side just set pm = pm.scaled(size()); in init. Don't know is it necessary or not.

                mrjjM 1 Reply Last reply
                0
                • G Gourmet

                  Yes, gotcha... just made QPixmap pm class-wide field and removed pm = grab(QRect(QPoint(0,0),size())); to another method before update() - and all is working. To be on safe side just set pm = pm.scaled(size()); in init. Don't know is it necessary or not.

                  mrjjM Offline
                  mrjjM Offline
                  mrjj
                  Lifetime Qt Champion
                  wrote on last edited by
                  #14

                  @Gourmet
                  It will grab it in its exact size.
                  So should not be needed.

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

                    It's not since in the constructor the size of the widget is still unknown.

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

                    G 1 Reply Last reply
                    0
                    • SGaistS SGaist

                      It's not since in the constructor the size of the widget is still unknown.

                      G Offline
                      G Offline
                      Gourmet
                      wrote on last edited by
                      #16

                      @SGaist
                      Not in constructor - Instead of this my widget has another init function called by plugin loader.

                      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