[osg-users] Qt5 QMdiArea
Émeric MASCHINO
emeric.maschino at gmail.com
Tue Aug 18 06:08:23 PDT 2015
Hi,
I don't remember how far my current code is from upstream osgviewerQt
example and Qt MDI sample, but here's how I did.
I started from the Qt MDI sample
(http://doc.qt.io/qt-5/qtwidgets-mainwindows-mdi-mdichild-h.html).
I've added the ViewerWidget class, inheriting from QWidget and
encompassing the OSG root node, viewer and rendering thread (I'm no
more using a QTimer) as member attributes.
I've modified the MdiChild class to inherit from ViewerWidget rather
than QTextEdit. Then in MdiChild::loadFile, I have:
bool MdiChild::loadFile(const QString &fileName)
{
#ifndef QT_NO_CURSOR
QApplication::setOverrideCursor(Qt::WaitCursor);
#endif
osg::Node* node = osgDB::readNodeFile(fileName.toStdString());
#ifndef QT_NO_CURSOR
QApplication::restoreOverrideCursor();
#endif
if (!node)
return false;
_root = new osg::Group;
_root->addChild(node);
QWidget* widget = addViewWidget(0, 0, width(), height(),
createGraphicsWindow(0, 0,
width(), height()),
_root.get());
QGridLayout* grid = new QGridLayout;
grid->addWidget(widget, 0, 0);
setLayout(grid);
setCurrentFile(fileName);
_renderingThread->start();
return true;
}
ViewerWidget::createGraphicsWindow creates the osgQt::GraphicsWindowQt
as in osgviewerQt example.
ViewerWidget::addViewWidget creates the OSG view, initializes the
manipulator, scene graph and camera configuration (as in osgviewerMFC
example), add the view to the OSG viewer member attribute and return
the GL widget of the Qt graphics context passed as an argument to
addViewWidget and created by createGraphicsWindow.
Hope this helps,
Émeric
2015-08-16 10:35 GMT+02:00 Vincent Majorczyk <vingt.sens at hotmail.fr>:
> Hi,
>
> I have tried to integrate the ViewerWidget (provided in the example 'osgviewerQt') to a QMdiArea, but this doesn't work. When the application start, I have empty 3D widgets. Nevertheless, popup windows works.
>
>
> Code:
> ViewerWidget* viewWidget = new ViewerWidget;
> viewWidget->createWindow();
>
> QMdiArea *area = new QMdiArea;
> area->addSubWindow(viewWidget);
>
> QMainWindow *m = new QMainWindow;
> m->setCentralWidget(area);
> m->show();
>
>
>
>
> I have modified the original implementation (class splitted to 'h'/'cpp' files; and construction of the widget in a method 'createWindow()'), nevertheless if I put viewWidget in the QMainWindows instead of the QMdiArea, there is no problem.
>
> I would like know if you have a solution to use QMdiArea.
> Thank you.
>
> Cheers,
> Vincent[/code]
>
> ------------------
> Read this topic online here:
> http://forum.openscenegraph.org/viewtopic.php?p=64788#64788
>
>
>
>
>
> _______________________________________________
> osg-users mailing list
> osg-users at lists.openscenegraph.org
> http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
-------------- next part --------------
A non-text attachment was scrubbed...
Name: osgviewerQt.png
Type: image/png
Size: 133073 bytes
Desc: not available
URL: <http://lists.openscenegraph.org/pipermail/osg-users-openscenegraph.org/attachments/20150818/9d7baf1b/attachment-0003.png>
More information about the osg-users
mailing list