Hi Qt Specialist,

I'm really desperate to make it work, I try different approaches but nothing works like expected. And most of the examples found by Googling concern Qt5.

First the Use Case: I have to do a color picker into a complex 2D scene, this scene is constructed with QSGNodes tree inside a QQuickItem. Of course, to make it more difficult, I have to pick the color without the drawing overlays and I should be able to pick outside of the item bounds.

I try this:
1. I create a simplified QQuickItem
2. try to bind it to an offscreen window (setParentItem & QQuickRenderControl)
3. add a render target (fromPaintDevice, I have no clue how to transform any 'kind' of textures into a QImage)
3. resize
4. render with polishItems, beginFrame, ....
5. check the image

I get this error:
QQuickWindow: No render target (neither swapchain nor custom target was provided)

Here is the code using Vulkan:
Qt Code:
  1. QVulkanInstance* inst = new QVulkanInstance;
  2. inst->create();
  3.  
  4. _render_ctrl = new QQuickRenderControl;
  5.  
  6. // this window will never be shown on-screen
  7. _off_screen_window = new QQuickWindow(_render_ctrl);
  8. _off_screen_window->setVulkanInstance(inst);
  9.  
  10. if (!_render_ctrl->initialize())
  11. qWarning() << "failed to init";
  12.  
  13. _image = new QImage(300, 200, QImage::Format_RGBA8888_Premultiplied);
  14. _image->fill(qRgb(255,255,0));
  15.  
  16. _off_screen_window->setRenderTarget(QQuickRenderTarget::fromPaintDevice(_image));
  17.  
  18. _off_screen_item->setParentItem(_off_screen_window->contentItem());
  19. _off_screen_item->setSize(QSize(300,200));
  20. _off_screen_item->setVisible(true);
  21.  
  22. _off_screen_window->resize(300, 200);
  23. //_off_screen_window->show();
  24.  
  25. _render_ctrl->polishItems();
  26. _render_ctrl->beginFrame();
  27. _render_ctrl->sync();
  28. _render_ctrl->render();
  29. _render_ctrl->endFrame();
  30.  
  31. _image->save("xxx.png"); // nothing draw just the original image
To copy to clipboard, switch view to plain text mode 

Could someone explain to me how in Qt6 I could render offscreen a QQuickItem in a QImage? Or at least into a texture and how to obtain an average color from the extracted texture?

Is the call QQuickWindow::setGraphicsApi(QSGRendererInterface: :Vulkan); compatible with the offscreen QQuickWindow? The Qt examples and documentation do not really cover this case.

The only solution, for now, I'm using (slow - no shaders to help - and need to duplicate the rendering) is the QPainter over a QImage.

Br,
Bilbon