[转][osg][QT]osg与QT界面结合的简单例子
//QT += core gui opengl
//LIBS += -losgViewer -losgDB -losgUtil -losg -lOpenThreads -losgGA -losgQt
#include <QtGui/QApplication>
#include <osg/ArgumentParser>
#include <osgViewer/Viewer>
#include <osgViewer/CompositeViewer>
#include <osgViewer/ViewerEventHandlers>
#include <osgGA/TrackballManipulator>
#include <osgDB/ReadFile>
#include <QtCore/QString>
#include <QtCore/QTimer>
#include <QtGui/QKeyEvent>
#include <QtGui/QApplication>
#include <QtOpenGL/QGLWidget>
#include <QtGui/QMainWindow>
#include <QtGui/QMdiSubWindow>
#include <QtGui/QMdiArea>
#include <iostream> using Qt::WindowFlags; class AdapterWidget:public QGLWidget
{
public:
AdapterWidget(QWidget *parent=,const char* name=,const QGLWidget * shareWidget=,WindowFlags f=); virtual ~AdapterWidget()
{ } osgViewer::GraphicsWindow* getGraphicsWindow()
{
return _gw.get();
} const osgViewer::GraphicsWindow* getGraphicsWidow()const
{
return _gw.get();
}
protected:
void init();
virtual void resizeGL(int width,int height);
virtual void keyPressEvent(QKeyEvent* event);
virtual void keyReleaseEvent(QKeyEvent* event);
virtual void mousePressEvent(QMouseEvent* event);
virtual void mouseReleaseEvent(QMouseEvent* event);//
virtual void mouseMoveEvent(QMouseEvent* event); osg::ref_ptr<osgViewer::GraphicsWindowEmbedded> _gw; }; AdapterWidget::AdapterWidget(QWidget *parent,const char* name,const QGLWidget * shareWidget,WindowFlags f):QGLWidget(parent,shareWidget,f)
{
_gw=new osgViewer::GraphicsWindowEmbedded(,,width(),height());
setFocusPolicy(Qt::ClickFocus); } void AdapterWidget::resizeGL(int width, int height)
{
_gw->getEventQueue()->windowResize(,,width,height);
_gw->resized(,,width,height); }
void AdapterWidget::keyPressEvent(QKeyEvent* event)
{
//_gw->getEventQueue()->keyPress( (osgGA::GUIEventAdapter::KeySymbol) *(event->text().toAscii().data() ) );
_gw->getEventQueue()->keyPress((osgGA::GUIEventAdapter::KeySymbol)*(event->text().toLatin1().data()));//qt5
} void AdapterWidget::keyReleaseEvent(QKeyEvent* event)
{
//_gw->getEventQueue()->keyRelease( (osgGA::GUIEventAdapter::KeySymbol)*(event->text().toAscii().data()));
_gw->getEventQueue()->keyRelease((osgGA::GUIEventAdapter::KeySymbol)*(event->text().toLatin1().data()));//qt5
} void AdapterWidget::mousePressEvent(QMouseEvent* event)
{
int button=;
switch (event->button())
{
case(Qt::LeftButton):
button=;
break;
case (Qt::MidButton):
button=;
break;
case (Qt::RightButton):
button=;
break;
case (Qt::NoButton):
button=;
break;
default:
button=;
break; } _gw->getEventQueue()->mouseButtonPress(event->x(),event->y(),button); } void AdapterWidget::mouseReleaseEvent( QMouseEvent* event )
{
int button = ;
switch(event->button())
{
case(Qt::LeftButton):
button = ;
break;
case(Qt::MidButton):
button = ;
break;
case(Qt::RightButton):
button = ;
break;
case(Qt::NoButton):
button = ;
break;
default:
button = ;
break;
}
_gw->getEventQueue()->mouseButtonRelease(event->x(), event->y(), button);
} void AdapterWidget::mouseMoveEvent(QMouseEvent* event)
{
_gw->getEventQueue()->mouseMotion(event->x(),event->y()); } class ViewerQT : public osgViewer::Viewer, public AdapterWidget
{
public:
ViewerQT(QWidget * parent=,const char * name=,const QGLWidget * shareWidget=,WindowFlags f=):AdapterWidget(parent ,name,shareWidget ,f)
{
getCamera()->setViewport(new osg::Viewport(,,width(),height()));
getCamera()->setProjectionMatrixAsPerspective(30.0f, static_cast<double>(width())/static_cast<double>(height()), 1.0f, 10000.0f);
getCamera()->setGraphicsContext(getGraphicsWindow()); setThreadingModel(osgViewer::Viewer::SingleThreaded);
connect(&_timer,SIGNAL(timeout()),this,SLOT(updateGL()));//并且把它的timeout()连接到适当的槽。当这段时间过去了,它将会发射timeout()信号。 _timer.start();//使用start()来开始 } virtual void paintGL()
{
frame();
}
protected:
QTimer _timer;
}; int main(int argc,char** argv)
{
/*
QTextCodec *xcodec = QTextCodec::codecForLocale();
QString exeDir = xcodec->toUnicode(QByteArray(argv[0]));
QString BKE_CURRENT_DIR = QFileInfo(exeDir).path();
QStringList libpath;
libpath << BKE_CURRENT_DIR + QString::fromLocal8Bit("/plugins/platforms");
libpath << BKE_CURRENT_DIR << BKE_CURRENT_DIR + QString::fromLocal8Bit("/plugins/imageformats");
libpath << BKE_CURRENT_DIR + QString::fromLocal8Bit("/plugins");
libpath << QApplication::libraryPaths();
QApplication::setLibraryPaths(libpath);
//以上是跑qt的环境变量
*/
QApplication a(argc,argv);
osg::ref_ptr<osg::Node> loadedModel=osgDB::readNodeFile("cow.osg");
ViewerQT * ViewerWindow=new ViewerQT;
ViewerWindow->setCameraManipulator(new osgGA::TrackballManipulator);
ViewerWindow->setSceneData(loadedModel.get()); QMainWindow* mw=new QMainWindow();
mw->showMaximized();
mw->setCentralWidget(ViewerWindow);
mw->show();
a.connect(&a,SIGNAL(lastWindowClosed()),&a,SLOT(quit()));
return a.exec();
}
转自:https://www.cnblogs.com/sangzaohaishui/p/4687771.html
注意:QGLWidget使用的库是:Qt5OpenGL.lib
[转][osg][QT]osg与QT界面结合的简单例子的更多相关文章
- [原][osg][QT]osg与QT界面结合的简单例子二
//main.cpp #include "VREObliqueEditorQTWindow.h" #include <QtWidgets/QApplication> # ...
- Robot Framework与Web界面自动化测试:简单例子
假设环境已经搭建好了.这里用RIDE( Robot Framework Test Data Editor)工具来编写用例.下面我们对Robot Framework简称rf. 我们先考虑下一个最基本的登 ...
- Qt osg QWidget osgViewer::Viewer
osgViewer::Viewer* _viewer = nullptr; _viewer = new osgViewer::Viewer;osg::ref_ptr<osg::Group> ...
- 用Qt写软件系列三:一个简单的系统工具之界面美化
前言 在上一篇中,我们基本上完成了主要功能的实现,剩下的一些导出.进程子模块信息等功能,留到后面再来慢慢实现.这一篇来讲述如何对主界面进行个性化的定制.Qt库提供的只是最基本的组件功能,使用这些组件开 ...
- qt widget设置Qt::FramelessWindowHint和Qt::WA_TranslucentBackground, 会出现一个bug: 在最小化后还原时界面停止刷新
qt widget设置Qt::FramelessWindowHint和Qt::WA_TranslucentBackground, 会出现一个bug: 在最小化后还原时界面停止刷新 Widget wit ...
- Qt 地址薄 (一) 界面设计
实现一个简单的地址薄,功能包括:地址的添加.浏览.编辑.查找.输出文件等. 1 界面和元素 整个地址薄界面,可视为一个 AddressBook 类.其中的 Name.Address 以及两个编辑栏, ...
- qml(Qt Quick)做界面
qml(Qt Quick)做界面 来源 https://www.zhihu.com/question/24880681/answer/29324824 本人是Qt初学者,正在写一个会计小软件(Lin ...
- [OpenCV Qt教程] 在Qt图形界面中显示OpenCV图像的OpenGL Widget(第二部分)
本文译自:http://www.robot-home.it/blog/en/software/tutorial-opencv-qt-opengl-widget-per-visualizzare-imm ...
- Qt常用的登录界面设计
记录一下Qt常用的登录界面的设计 方便以后使用! 1.QpushButton改变一个按钮的颜色,当鼠标放上去和移开时显示不同的颜色.QPushButton { background-color: rg ...
随机推荐
- html介绍和head标签
一.web标准 web准备介绍: w3c:万维网联盟组织,用来制定web标准的机构(组织) web标准:制作网页遵循的规范 web准备规范的分类:结构标准.表现标准.行为标准. 结构:html.表 ...
- spring总结之二(Bean作用域、依赖注入)
### Bean的作用域:单例(singleton),多例(prototype) 1.单例模式:表示在任何地方使用对象,总是一个(对象是唯一的). (笔面试重点) 饿汉式 public class K ...
- shell 中的小技巧
去掉最后一个字符 sed 's/.$//' awk '{sub(/.$/,"")}1' awk '{printf $0"\b \n"}' [root@ ~]# ...
- 深入理解Word2Vec
Word2Vec Tutorial - The Skip-Gram Model,Skip-Gram模型的实现原理:http://mccormickml.com/2016/04/19/word2vec- ...
- Mysql 存储过程中使用多游标
Mysql 存储过程中使用多游标 drop procedure IF EXISTS test_proc_1; create procedure test_proc_1() begin ; ) ; ) ...
- 02: git分支管理
目录:GIT其他篇 01: git & github 02: git分支管理 目录: 1.1 Git常用命令 1.2 主要分支(保护分支) 1.3 特性分支:feature (开发分支合并到d ...
- 06:vuejs项目实战
1.1 项目说明 1.技术架构 vue.js, 模块化,工程化, 移动端 2.目录部署 Css:所有样式文件 Data:所有异步接口 Img:所有图片文件 Js:所有js文件(2.0) index.h ...
- metasploit(MSF)对windows的ms17-010漏洞利用
picture 配置exploit msf > use exploit/windows/smb/ms17_010_eternalblue msf exploit(windows/smb/ms17 ...
- python简说(十五)MD5加密
def my_md5(s): news = str(s).encode() m = hashlib.md5(news) return m.hexdigest()
- MSF基础应用
实践目标 掌握metasploit的基本应用方式. 具体需要完成(1)ms08_067;(2)ms11_050:(3)Adobe(4)成功应用任何一个辅助模块. 报告 虚拟机:可以找我拷贝(我一般都在 ...