<div dir="ltr"><div>Hi   <span class="_username"><span class="F0XO1GC-F-a" style="color: rgb(34, 34, 34);">Angelo,</span></span></div><div><span class="_username"><span class="F0XO1GC-F-a" style="color: rgb(34, 34, 34);"><span style="font-weight: normal;"><br></span></span></span></div><div><span class="_username"><span class="F0XO1GC-F-a" style="color: rgb(34, 34, 34);"><span style="font-weight: normal;"><font size="2">I believe you should handle from the osgQOpenGLWidget virtual methods, which should be something like </font></span></span></span><span class="_username"><span class="F0XO1GC-F-a" style="color: rgb(34, 34, 34);"><span style="font-weight: normal;"><font size="2"><span style=" font-style:italic; color:#45c6d6;">virtual</span><span style=" color:#bec0c2;"> </span><span style=" color:#d69aa7;">void</span><span style=" color:#bec0c2;"> </span>resizeGL(<span style=" color:#bec0c2;"> </span><span style=" color:#d69aa7;">int</span><span style=" color:#bec0c2;"> </span>width,<span style=" color:#bec0c2;"> </span><span style=" color:#d69aa7;">int</span><span style=" color:#bec0c2;"> </span>height<span style=" color:#bec0c2;"> </span>); <br></font></span></span></span></div><div><span class="_username"><span class="F0XO1GC-F-a" style="color: rgb(34, 34, 34);"><span style="font-weight: normal;"><font size="2">As it's expected it should be called whenever there's a change in the widget size. From there you would be able to call </font></span></span></span><span class="_username"><span class="F0XO1GC-F-a" style="color: rgb(34, 34, 34);"><span style="font-weight: normal;"><font size="2"><span style=" color:#ff8080;">osgViewer</span>::<span style=" color:#ff8080;">GraphicsWindowEmbedded </span>resized method as <br></font></span></span></span></div><div><span class="_username"><span class="F0XO1GC-F-a" style="color: rgb(34, 34, 34);"><span style="font-weight: normal;"><font size="2">well as camera's necessary adjustment for the new size and most important the aspect ration for this new size.<br></font></span></span></span></div><div><span class="_username"><span class="F0XO1GC-F-a" style="color: rgb(34, 34, 34);"><br></span></span></div><div><span class="_username"><span class="F0XO1GC-F-a" style="color: rgb(34, 34, 34);"><br></span></span></div>On Thursday, February 20, 2020 at 3:12:43 PM UTC+1, Angelo Emanuele Fiorilla wrote:<blockquote class="gmail_quote" style="margin: 0;margin-left: 0.8ex;border-left: 1px #ccc solid;padding-left: 1ex;"><div dir="ltr">Hi,<div>I am trying to put an osgQOpenGLWidget inside a QMainWindow. I managed to made it quite easily but the resulting image is stretched and I cannot change its aspect ratio to made it right (the cow.osg is really stretched).</div><div>Can you help me, please? I have been struggling with this few lines of code for 5 days now.</div><div><br></div><div>I can provide source code as follows...</div><div><br></div><div>Thank you so much</div><div><br></div><div><pre style="background-color:#2b2b2b;color:#a9b7c6;font-family:'DejaVu Sans Mono';font-size:9.0pt"><span style="color:#bbb529">#include </span><span style="color:#6a8759">"mainwindow.h"<br></span><span style="color:#6a8759"><br></span><span style="color:#b5b6e3">MainWindow</span>::<span style="color:#ffc66d">MainWindow</span>(<span style="color:#b5b6e3">QWidget </span>*parent)<br>        : <span style="color:#b5b6e3">QMainWindow</span>(parent)<br>{<br>    <span style="color:#b5b6e3">QSurfaceFormat </span>format = <span style="color:#b5b6e3">QSurfaceFormat</span>::defaultFormat(<wbr>)<span style="color:#cc7832">;<br></span><span style="color:#cc7832">    </span>format.setVersion(<span style="color:#6897bb">2</span><span style="color:#cc7832">, </span><span style="color:#6897bb">0</span>)<span style="color:#cc7832">;<br></span><span style="color:#cc7832">    </span>format.setProfile(<span style="color:#b5b6e3">QSurfaceForm<wbr>at</span>::<span style="color:#9876aa;font-style:italic">CompatibilityProfile</span>)<span style="color:#cc7832">;<br></span><span style="color:#cc7832">    </span>format.setRenderableType(<span style="color:#b5b6e3">QSurf<wbr>aceFormat</span>::<span style="color:#9876aa;font-style:italic">OpenGL</span>)<span style="color:#cc7832">;<br></span><span style="color:#cc7832">    </span>format.setOption(<span style="color:#b5b6e3">QSurfaceForma<wbr>t</span>::<span style="color:#9876aa;font-style:italic">DebugContext</span>)<span style="color:#cc7832">;<br></span><span style="color:#cc7832">    </span>format.setDepthBufferSize(<span style="color:#6897bb">24</span>)<span style="color:#cc7832">;<br></span><span style="color:#cc7832">    </span>format.setSamples(<span style="color:#6897bb">8</span>)<span style="color:#cc7832">;<br></span><span style="color:#cc7832">    </span>format.setStencilBufferSize(<span style="color:#6897bb">8</span>)<span style="color:#cc7832"><wbr>;<br></span><span style="color:#cc7832">    </span>format.setSwapBehavior(<span style="color:#b5b6e3">QSurfac<wbr>eFormat</span>::<span style="color:#9876aa;font-style:italic">DoubleBuffer</span>)<span style="color:#cc7832">;<br></span><span style="color:#cc7832">    </span><span style="color:#b5b6e3">QSurfaceFormat</span>::<wbr>setDefaultFormat(format)<span style="color:#cc7832">;<br></span><span style="color:#cc7832"><br></span><span style="color:#cc7832">    </span><span style="color:#9373a5">osgWidget </span>= <span style="color:#cc7832">new </span><span style="color:#b5b6e3">osgQOpenGLWidget</span>(<span style="color:#cc7832">this</span>)<span style="color:#cc7832">;<br></span><span style="color:#cc7832">    </span><span style="color:#b5b6e3">QObject</span>::connect(<span style="color:#9373a5">osgWidget</span><span style="color:#cc7832">, </span>&<span style="color:#b5b6e3">osgQOpenGLWidget</span>::initialized<span style="color:#cc7832"><wbr>, this, </span>&<span style="color:#b5b6e3">MainWindow</span>::setupOsgView)<span style="color:#cc7832">;<br></span><span style="color:#cc7832"><br></span><span style="color:#808080">    </span>setCentralWidget(<span style="color:#9373a5">osgWidget</span>)<span style="color:#cc7832">;<br></span><span style="color:#cc7832">    </span><span style="color:#9373a5">osgWidget</span>->show()<span style="color:#cc7832">;<br></span>}<br><br><span style="color:#cc7832">void </span><span style="color:#b5b6e3">MainWindow</span>::<span style="color:#ffc66d">setupOsgView</span>() {<br><br>    <span style="color:#9373a5">osgWidget</span>->getOsgViewer()-><wbr>setCameraManipulator(<span style="color:#cc7832">new </span><span style="color:#b5b6e3">osgGA</span>::<span style="color:#b5b6e3">TerrainManipulator</span>())<span style="color:#cc7832">;<br></span><span style="color:#cc7832">    </span><span style="color:#9373a5">osgWidget</span>->getOsgViewer()-><wbr>addEventHandler(<span style="color:#cc7832">new </span><span style="color:#b5b6e3">osgGA</span>::<span style="color:#b5b6e3">StateSetManipulator</span>(<span style="color:#9373a5">osg<wbr>Widget</span>->getOsgViewer()-><wbr>getCamera()-><wbr>getOrCreateStateSet()))<span style="color:#cc7832">;<br></span><span style="color:#cc7832">    </span><span style="color:#9373a5">osgWidget</span>->getOsgViewer()-><wbr>addEventHandler(<span style="color:#cc7832">new </span><span style="color:#b5b6e3">osgViewer</span>::<span style="color:#b5b6e3">ThreadingHandler</span>)<span style="color:#cc7832">;<br></span><span style="color:#cc7832">    </span><span style="color:#9373a5">osgWidget</span>->getOsgViewer()-><wbr>addEventHandler(<span style="color:#cc7832">new </span><span style="color:#b5b6e3">osgViewer</span>::<span style="color:#b5b6e3">WindowSizeHandler</span>)<span style="color:#cc7832">;<br></span><span style="color:#cc7832">    </span><span style="color:#9373a5">osgWidget</span>->getOsgViewer()-><wbr>addEventHandler(<span style="color:#cc7832">new </span><span style="color:#b5b6e3">osgViewer</span>::<span style="color:#b5b6e3">StatsHandler</span>)<span style="color:#cc7832">;<br></span><span style="color:#cc7832">    </span><span style="color:#9373a5">osgWidget</span>->getOsgViewer()-><wbr>addEventHandler(<span style="color:#cc7832">new </span><span style="color:#b5b6e3">osgViewer</span>::<span style="color:#b5b6e3">RecordCameraPathHan<wbr>dler</span>)<span style="color:#cc7832">;<br></span><span style="color:#cc7832">    </span><span style="color:#9373a5">osgWidget</span>->getOsgViewer()-><wbr>addEventHandler(<span style="color:#cc7832">new </span><span style="color:#b5b6e3">osgViewer</span>::<span style="color:#b5b6e3">LODScaleHandler</span>)<span style="color:#cc7832">;<br></span><span style="color:#cc7832">    </span><span style="color:#9373a5">osgWidget</span>->getOsgViewer()-><wbr>addEventHandler(<span style="color:#cc7832">new </span><span style="color:#b5b6e3">osgViewer</span>::<span style="color:#b5b6e3">ScreenCaptureHandle<wbr>r</span>)<span style="color:#cc7832">;<br></span><span style="color:#cc7832"><br></span><span style="color:#cc7832">    </span><span style="color:#b5b6e3">osg</span>::<span style="color:#b5b6e3">ref_ptr</span><<span style="color:#b5b6e3">osg</span>::<span style="color:#b5b6e3">Node</span>> loadedModel = <span style="color:#b5b6e3">osgDB</span>::readRefNodeFile(<span style="color:#6a8759">"cow.<wbr>osg"</span>)<span style="color:#cc7832">;<br></span><span style="color:#cc7832">    if</span>(<span style="color:#5f8c8a">!</span>loadedModel) {<br>        <span style="color:#b5b6e3">std</span>::cout <span style="color:#5f8c8a"><< </span><span style="color:#6a8759">"No data loaded" </span><span style="color:#5f8c8a"><< </span><span style="color:#b5b6e3">std</span>::endl<span style="color:#cc7832">;<br></span><span style="color:#cc7832">    </span>}<br><br>    <span style="color:#b5b6e3">osgUtil</span>::<span style="color:#b5b6e3">Optimizer </span>optimizer<span style="color:#cc7832">;<br></span><span style="color:#cc7832">    </span>optimizer.optimize(<wbr>loadedModel)<span style="color:#cc7832">;<br></span><span style="color:#cc7832"><br></span><span style="color:#cc7832">    </span><span style="color:#9373a5">osgWidget</span>->getOsgViewer()-><wbr>setSceneData(loadedModel)<span style="color:#cc7832">;<br></span>}<br><br><span style="color:#b5b6e3">MainWindow</span>::<span style="color:#ffc66d">~MainWindow</span>()<br>{<br><br>}</pre></div></div></blockquote></div>

<p></p>

-- <br />
You received this message because you are subscribed to the Google Groups "OpenSceneGraph Users" group.<br />
To unsubscribe from this group and stop receiving emails from it, send an email to <a href="mailto:osg-users+unsubscribe@googlegroups.com">osg-users+unsubscribe@googlegroups.com</a>.<br />
To view this discussion on the web visit <a href="https://groups.google.com/d/msgid/osg-users/dcfa7c78-c750-428c-ae4a-8db831fed0a2%40googlegroups.com?utm_medium=email&utm_source=footer">https://groups.google.com/d/msgid/osg-users/dcfa7c78-c750-428c-ae4a-8db831fed0a2%40googlegroups.com</a>.<br />