
Wed, 03/26/2025 - 17:19
I have such a requirement, I need to build the software in linux with qt, and embed OCCT in the middle of the software. Currently, the embedding can be completed, but there is a problem, when I render the embedded OCCT, the occt control cannot fill the display, as shown in the following figure,The specific code is as follows:
bool OcctCore::InitViewer()
{
Handle(Aspect_DisplayConnection) aDisplayConnection=new Aspect_DisplayConnection();
myGraphicDriver = new OpenGl_GraphicDriver(aDisplayConnection);
myViewer = new V3d_Viewer(myGraphicDriver);
myViewer->SetDefaultLights();
myViewer->SetLightOn();
myView = myViewer->CreateView();
myView->SetProj(V3d_Zpos);
WId window_handle = (WId) winId();
Handle(Xw_Window) awin= new Xw_Window(aDisplayConnection,(Window)window_handle);
awin->BackgroundFillMethod();
myView->SetWindow(awin);
if (!awin->IsMapped())
{
awin->Map();
}
myAISContext = new AIS_InteractiveContext(myViewer);
myViewer->SetDefaultLights();
myViewer->SetLightOn();
myView->MustBeResized();
myView->TriedronDisplay(Aspect_TOTP_LEFT_LOWER, Quantity_NOC_WHITE, 0.1, V3d_ZBUFFER);
Handle(AIS_ViewCube) viewCube = new AIS_ViewCube();
viewCube->SetTransformPersistence(
new Graphic3d_TransformPers(
Graphic3d_TMF_TriedronPers,
Aspect_TOTP_RIGHT_UPPER/*设置在右下角*/,
Graphic3d_Vec2i(100, 100)));
myAISContext->Display(viewCube, Standard_True);
Quantity_Color color1(Quantity_NOC_SKYBLUE);
Quantity_Color color2(Quantity_NOC_SKYBLUE4);
myView->SetBgGradientColors(color1, color2, Aspect_GradientFillMethod_Vertical);
myView->ChangeRenderingParams().ToShowStats = true;
TopoDS_Shape aTopoBox = BRepPrimAPI_MakeBox(3.0, 4.0, 5.0).Shape();
Handle(AIS_Shape) anAisBox = new AIS_Shape(aTopoBox);
anAisBox->SetColor(Quantity_NOC_AZURE);
myAISContext->Display(anAisBox, Standard_True);
myAISContext->SetDisplayMode(AIS_Shaded, Standard_True);
myView->FitAll();
return true;
}
QWidget* occtContainer = new QWidget();
// 使用网格布局确保OCCT视图填满整个中央区域
QGridLayout* layout = new QGridLayout(occtContainer);
setCentralWidget(occtContainer);
layout->setContentsMargins(0, 0, 0, 0);
// 使用渐变背景色
// occtContainer->setStyleSheet(
// "background: qlineargradient(x1:0, y1:0, x2:1, y2:1, "
// "stop:0 #2A3F54, stop:1 #1A2B3C);"
// );
layout->setSpacing(0);
OcctCore* occt=new OcctCore(occtContainer);
layout->addWidget(occt);
Thank you very much for helping me. Give me a plan to determine how I can ensure that the embedded widget fills the form during my embedding process