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. Trying to grab/render a pixmap from a Qt3DWindow
QtWS25 Last Chance

Trying to grab/render a pixmap from a Qt3DWindow

Scheduled Pinned Locked Moved Unsolved General and Desktop
qt3dwindowpixmap
9 Posts 2 Posters 956 Views
  • 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.
  • D Offline
    D Offline
    DeadComposer
    wrote on 22 Sept 2023, 12:12 last edited by
    #1

    I'm creating a Qt3DWindow in a window container, then using render() to get a pixmap from the window container (I can't render() from the Qt3DWindow itself because it's not a QWidget). When I save the pixmap to a PNG file it turns up empty. The 3D entities I added are nowhere to be seen.

    I know there's a grabWindow function that might work, but it's not perfect because any windows that overlap the Qt3DWindow would be copied into the pixmap as well. Does anyone know how I can do this? Thanks.

    self.extrude_window = Qt3DExtras.Qt3DWindow()
    self._windowContainer = QtWidgets.QWidget.createWindowContainer(self.extrude_window)

    add graphical entities

    pix = QtGui.QPixmap(self._windowContainer.width(), self._windowContainer.height())
    self._windowContainer.render(pix)
    pix.save(file_name, 'PNG') # resulting PNG file is empty

    1 Reply Last reply
    0
    • S Offline
      S Offline
      SGaist
      Lifetime Qt Champion
      wrote on 22 Sept 2023, 18:17 last edited by
      #2

      Hi and welcome to devnet,

      Was the widget ever shown before you call render ?

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

      D 1 Reply Last reply 22 Sept 2023, 18:25
      0
      • S SGaist
        22 Sept 2023, 18:17

        Hi and welcome to devnet,

        Was the widget ever shown before you call render ?

        D Offline
        D Offline
        DeadComposer
        wrote on 22 Sept 2023, 18:25 last edited by
        #3

        @SGaist The widget is visible at the time that render is called. I'm using PySide6, incidentally. There's also a QWindow in the same application for which the grab() function successfully obtains a pixmap with the correct contents.

        S 1 Reply Last reply 22 Sept 2023, 18:28
        0
        • D DeadComposer
          22 Sept 2023, 18:25

          @SGaist The widget is visible at the time that render is called. I'm using PySide6, incidentally. There's also a QWindow in the same application for which the grab() function successfully obtains a pixmap with the correct contents.

          S Offline
          S Offline
          SGaist
          Lifetime Qt Champion
          wrote on 22 Sept 2023, 18:28 last edited by
          #4

          Can you provide a minimal script example showing this behaviour ?

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

          D 1 Reply Last reply 22 Sept 2023, 18:37
          0
          • S SGaist
            22 Sept 2023, 18:28

            Can you provide a minimal script example showing this behaviour ?

            D Offline
            D Offline
            DeadComposer
            wrote on 22 Sept 2023, 18:37 last edited by
            #5

            @SGaist
            // create a Qt3DWindow
            self.extrude_window = PySide6.Qt3DExtras.Qt3DWindow()
            // put it in a window container to make it behave like a widget
            self._windowContainer = QtWidgets.QWidget.createWindowContainer(self.extrude_window)

            // Add a series of QCuboidMesh entities to a root entity, then
            // assign the root entity to the Qt3DWindow
            // Assign a material and a transform to each of the cubic entities

            // Create a pixmap to hold the contents of the window container, which should theoretically include the contents of the Qt3DWindow as well
            pix = QtGui.QPixmap(self._windowContainer.width(), self._windowContainer.height())
            // Render the window container to the pixmap
            self._windowContainer.render(pix)
            // Save the pixmap to a PNG file
            pix.save(file_name, 'PNG') # resulting PNG file is empty

            D 1 Reply Last reply 22 Sept 2023, 18:47
            0
            • D DeadComposer
              22 Sept 2023, 18:37

              @SGaist
              // create a Qt3DWindow
              self.extrude_window = PySide6.Qt3DExtras.Qt3DWindow()
              // put it in a window container to make it behave like a widget
              self._windowContainer = QtWidgets.QWidget.createWindowContainer(self.extrude_window)

              // Add a series of QCuboidMesh entities to a root entity, then
              // assign the root entity to the Qt3DWindow
              // Assign a material and a transform to each of the cubic entities

              // Create a pixmap to hold the contents of the window container, which should theoretically include the contents of the Qt3DWindow as well
              pix = QtGui.QPixmap(self._windowContainer.width(), self._windowContainer.height())
              // Render the window container to the pixmap
              self._windowContainer.render(pix)
              // Save the pixmap to a PNG file
              pix.save(file_name, 'PNG') # resulting PNG file is empty

              D Offline
              D Offline
              DeadComposer
              wrote on 22 Sept 2023, 18:47 last edited by
              #6

              Also, the Qt3DWindow is one child of a QStackedWidget. The other child of the QStackedWidget is a QWindow, and as I mentioned before, the grab() of the QWindow returns a valid pixmap containing all of the window's contents (which are then successfully saved to a PNG file).

              D 1 Reply Last reply 22 Sept 2023, 23:40
              0
              • D DeadComposer
                22 Sept 2023, 18:47

                Also, the Qt3DWindow is one child of a QStackedWidget. The other child of the QStackedWidget is a QWindow, and as I mentioned before, the grab() of the QWindow returns a valid pixmap containing all of the window's contents (which are then successfully saved to a PNG file).

                D Offline
                D Offline
                DeadComposer
                wrote on 22 Sept 2023, 23:40 last edited by
                #7

                Update: I tried passing the QWidget.DrawChildren flag into _windowContainer.render() as the renderFlags argument. This time, instead of getting a blank PNG file from the pixmap, I got a PNG file of scrambled color streaks, as if the number of pixels per row in the image didn't match the horizontal resolution in the PNG.

                D 1 Reply Last reply 22 Sept 2023, 23:55
                0
                • D DeadComposer
                  22 Sept 2023, 23:40

                  Update: I tried passing the QWidget.DrawChildren flag into _windowContainer.render() as the renderFlags argument. This time, instead of getting a blank PNG file from the pixmap, I got a PNG file of scrambled color streaks, as if the number of pixels per row in the image didn't match the horizontal resolution in the PNG.

                  D Offline
                  D Offline
                  DeadComposer
                  wrote on 22 Sept 2023, 23:55 last edited by
                  #8

                  Maybe this is important too: When the Qt3DWindow renders its shapes (to the display, not to the pixmap), there is a series of "Xlib: sequence lost (...) in reply type 0x0!" error messages.

                  1 Reply Last reply
                  0
                  • D Offline
                    D Offline
                    DeadComposer
                    wrote on 10 Feb 2024, 00:00 last edited by
                    #9

                    Has any progress been made on this problem? I'm still encountering it. If it helps at all, I'm running on a Linux system with noVNC.

                    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