Important: Please read the Qt Code of Conduct -

Retrieving a large list of objects from C++ for Qt3D Quick display

  • I am writing an application that will let users pick stuff from a scrollable list of objects(represented as icons in the list). Then drop them to a 3D Viewer. Then the user clicks 'Play' and these objects move.

    Its for a physics simulation where the objects to be added are in the list. So the interface is quite simple and I wanted to create it in QML. The simulation classes are in C++ (Bullet Physics). I am planning to make the 3D Viewer where the objects can be seen moving(following the laws of physics), in Qt3D Quick.

    The way I am hoping to make this work is, the 3D Viewer calls 2 C++ functions in each frame :

    1. stepSimulation() - does the simulation for the time elapsed since the last call, very small intervals are buffered
    2. retrieveObjects - this gets the list of objects from the C++ code.

    My concern is how to achieve (2). Is it possible to retrieve a std::vector<MyObjectCLass> from C++ into QML ?

    Also does Qt3D Quick support moderately complex 3D scenes and camera movements. How about GLSL shaders ?

    How would one go about achieving drag and drop functionality in this application. Here users would pick from the scrollable list and drag to the 3D Viewer - just like in Maya or 3DS Max. So the Qt3D Quick view should be able to accept the drag and drop event.

  • Hello and welcome to,

    i may not help you about the Qt3D part, but maybe the drag and drop part. Are these objects which you want to drag and drop size-fixed? If so, then you can use a ListView or GridView.

    For further information and examples please read: "Drag and Drop":

    If you want to have custom cells, then you have to create your own handler for this. Currently i am working on a handler which has got custom dragable components as childs and a mesh where he looks the grids up. The childs trigger a function in the Handler passing their new coordinates, the handler looks up in the table and updates all components based on the new position of the component.

  • Thanks for the reply. Here is what I have in mind :

    @ _______________________________________________
    |O1|O2|||||| <----- List of icons
    | |
    | | |
    | | _____ <-------3D Viewer
    | / |
    _____ ________________________|
    |<---------controls @

  • What do you want to have drag and dropable? Only the list of icons or everything including your controls and the viewer so you can reposition as needet?

  • Only the list of icons. So the user clicks something in the list and then drags it to the 3D Viewer. Then this sphere or cube appears in the 3D Viewer when the drag is complete.

    I do not need drag and drop necessarily of course as the user can simply click on the icon in the list of objects then click again in the 3D Viewer viewport, and then the object appears there - in that case we do not need the drag and drop of course, but it would be good to have :)

    The position of the controls are fixed as they are for controlling the simulation so the user should not mess with them.

  • Alright so it is basically just a drag. For that you can use a MouseArea as a child of each Icon:
    @MouseArea { parent
    drag.axis: Drag.XAndYAxis
    onReleased {
    if(MouseX >= 3dviewer.x && MouseX <= 3dviewer.x+3dviewer.width){
    if(MouseX >= 3dviewer.y && MouseY <= 3dviewer.y+3dviewer.height){
    // Inside the 3d viewer, display it in 3d
    //dont let it drop here just let it move back to it's position

    It may be not 100% correct because i have typed it in the reply-box and not in Qt. But it should look somehow like that. Also don't forget to set drag.MinimumX / drag.MinimumY and drag.MaximumX / drag.MaximumY.

    For further information please read: "MouseArea":

  • Thanks. I will try it out. What do you mean by

    bq. let it move back to it's position.

    Also I need to have a MouseArea for every icon ? So if there are 100 icons, then each need one ? Or can I just have MouseAreas for the ones currently visible in the list.

    The list of icons is just like a sideways scrolling roll of photos as can be seen in the Flickr photo viewing app for example. There will be an arrow at the right side to allow scrolling further right to see more object icons. The icons which are no longer visible do not need MouseAreas I guess. Maybe I can put in some logic to implement that.

  • By "let it move back to it's position." i mean that your icon should move back to it's position in the list of icons and not disappear.

    Well you probably will need a MouseArea for each Icon, but you could also assign them dynamically like you probably will do with your icons, so each icon will have a child mousearea which behavors like it is the child of a icon.

    You are probably using a ListView for your Iconlist so a icon would be a delegate of it, and so would be the MouseArea so only visible MouseAreas are dragable and "available".
    Otherwise you could check in onXChanged or onYChanged if your MouseArea is in the visible Area or not and handle that somehow.

Log in to reply