OpenCascade 7.4 Qt 5.15 Visualization

I am attempting to create a Qt application in C++ which incorporates a 3D OCC visualization. I am new to OpenCascade and Qt and would like to put the visualization in a frame or widget, so that I can incorprate it into a layout. Does anyone know what I can do to get a simple 3D visualization to work inside of a QWidget/QFrame?

Thanks in advance.

Francois Lauzon's picture

Hello,

just take a look at the OCC Qt Samples, there is example there with QML and with QWidgets.

Best regards,

François.

Lenlend Kibak's picture

you need to bind the winId of Qwidget to the v3d_view. The sample code is follow:

    Handle(V3d_View) aView;
    Handle(AIS_InteractiveContext) aContext;
    Handle(V3d_Viewer) aViewer;

    Handle(WNT_Window) window;

    Handle(Aspect_DisplayConnection) aDisplayConnection = new Aspect_DisplayConnection();
    Handle(Graphic3d_GraphicDriver) aGraphicDriver;
    if(aGraphicDriver.IsNull())
    {
        aGraphicDriver = new OpenGl_GraphicDriver(aDisplayConnection);
    }

    Handle(V3d_Viewer) aViewer = new V3d_Viewer(aGraphicDriver);


    aViewer->SetDefaultLights();
    aViewer->SetLightOn();
    aViewer->ActivateGrid(Aspect_GridType::Aspect_GT_Rectangular,Aspect_GridDrawMode::Aspect_GDM_Lines);

    window = new WNT_Window((Aspect_Handle) windowId);
    if(!window->IsMapped())
    {
        window->Map();
    }
    window->SetBackground(Quantity_Color(1.,1.,1.,Quantity_TypeOfColor::Quantity_TOC_RGB));

    aView = aViewer->CreateView();
    aView->MustBeResized();
    aView->SetWindow(window);
    aView->SetBgGradientColors(Quantity_Color(1.,1.,1.,Quantity_TypeOfColor::Quantity_TOC_RGB),
                               Quantity_Color(0.4,0.6,0.8,Quantity_TypeOfColor::Quantity_TOC_RGB),
                               Aspect_GradientFillMethod::Aspect_GFM_DIAG1,Standard_True);
    aView->ZBufferTriedronSetup(Quantity_NOC_RED,Quantity_NOC_BLUE1 ,Quantity_NOC_GREEN ,1,0.05,12);
    aView->TriedronDisplay(Aspect_TOTP_LEFT_UPPER,Quantity_NOC_RED,
                           0.08,V3d_ZBUFFER);
    aView->SetImmediateUpdate(Standard_True);

    aContext = new AIS_InteractiveContext(aViewer);
    aContext->SetDisplayMode(AIS_DisplayMode::AIS_Shaded,Standard_True);

The windowID above is the id of the Qwidget which you want to bind.

At last you need to redraw the view in the paintEvent of Qwidget.

void paintEvent(QPaintEvent *e)
{
    aOccViewer->aView->Redraw();
}

if you want to display the shape, you can use aContext->Display().