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. Is there any easy way to generate a bitmap of an QWindow?
Forum Updated to NodeBB v4.3 + New Features

Is there any easy way to generate a bitmap of an QWindow?

Scheduled Pinned Locked Moved Unsolved General and Desktop
5 Posts 3 Posters 1.1k Views 1 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 Offline
    M Offline
    MartinChan 0
    wrote on last edited by
    #1

    I am recently use QtOpenGL and I imitate the example of "Qt OpenGL Window" to subclass the QWindow class to draw my polygon.One step in my task is to output the content in bitmap way of the window.So,is there any easy way to output the content in QWindow?Before I use the OpenGL "glGetRead" function to get the pixel value to solve this question .

    m.sueM 1 Reply Last reply
    0
    • M MartinChan 0

      I am recently use QtOpenGL and I imitate the example of "Qt OpenGL Window" to subclass the QWindow class to draw my polygon.One step in my task is to output the content in bitmap way of the window.So,is there any easy way to output the content in QWindow?Before I use the OpenGL "glGetRead" function to get the pixel value to solve this question .

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

      Hi @MartinChan-0

      I would try to use the grabWindow function of the window's QScreen. Something like the following:

      QScreen *screen=myWindow->screen();
      QPixmap pixmap=screen->grabWindow(myWindow->winId());
      

      (Never tested it, though.)

      -Michael.

      M 1 Reply Last reply
      0
      • S Offline
        S Offline
        Swerved
        wrote on last edited by
        #3

        Much simpler, this example will save a png to disk. If you need to return the pixmap instead that's easy to do:

        QPixmap::grabWindow(QApplication::desktop()->winId()).save(QString(location+".png"));
        
        M 1 Reply Last reply
        0
        • m.sueM m.sue

          Hi @MartinChan-0

          I would try to use the grabWindow function of the window's QScreen. Something like the following:

          QScreen *screen=myWindow->screen();
          QPixmap pixmap=screen->grabWindow(myWindow->winId());
          

          (Never tested it, though.)

          -Michael.

          M Offline
          M Offline
          MartinChan 0
          wrote on last edited by
          #4

          @m.sue Thx man,I will try it later~

          1 Reply Last reply
          0
          • S Swerved

            Much simpler, this example will save a png to disk. If you need to return the pixmap instead that's easy to do:

            QPixmap::grabWindow(QApplication::desktop()->winId()).save(QString(location+".png"));
            
            M Offline
            M Offline
            MartinChan 0
            wrote on last edited by
            #5

            @Swerved Thx man~

            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