diff --git a/src/osgqt/GraphicsWindowQt.cpp b/src/osgqt/GraphicsWindowQt.cpp index e40d626c..bec3fbfe 100644 --- a/src/osgqt/GraphicsWindowQt.cpp +++ b/src/osgqt/GraphicsWindowQt.cpp @@ -850,19 +850,22 @@ bool GraphicsWindowQt::releaseContextImplementation() void GraphicsWindowQt::swapBuffersImplementation() { - _widget->swapBuffers(); + if (_widget->isVisible()) + { + _widget->swapBuffers(); - // FIXME: the processDeferredEvents should really be executed in a GUI (main) thread context but - // I couln't find any reliable way to do this. For now, lets hope non of *GUI thread only operations* will - // be executed in a QGLWidget::event handler. On the other hand, calling GUI only operations in the - // QGLWidget event handler is an indication of a Qt bug. - if (_widget->getNumDeferredEvents() > 0) - _widget->processDeferredEvents(); + // FIXME: the processDeferredEvents should really be executed in a GUI (main) thread context but + // I couln't find any reliable way to do this. For now, lets hope non of *GUI thread only operations* will + // be executed in a QGLWidget::event handler. On the other hand, calling GUI only operations in the + // QGLWidget event handler is an indication of a Qt bug. + if (_widget->getNumDeferredEvents() > 0) + _widget->processDeferredEvents(); - // We need to call makeCurrent here to restore our previously current context - // which may be changed by the processDeferredEvents function. - if (QGLContext::currentContext() != _widget->context()) - _widget->makeCurrent(); + // We need to call makeCurrent here to restore our previously current context + // which may be changed by the processDeferredEvents function. + if (QGLContext::currentContext() != _widget->context()) + _widget->makeCurrent(); + } } void GraphicsWindowQt::requestWarpPointer( float x, float y ) diff --git a/src/viewer/OsgWidget.cpp b/src/viewer/OsgWidget.cpp index 1200f786..1c190217 100644 --- a/src/viewer/OsgWidget.cpp +++ b/src/viewer/OsgWidget.cpp @@ -206,6 +206,15 @@ void OsgWidget::paintEvent(QPaintEvent*) { frame(); } +void OsgWidget::showEvent(QShowEvent * event) +{ + if (nullptr == view_) { + return; + } + qreal devicePixelRatio = screen()->devicePixelRatio(); + viewUI_->Resize(size().width() * devicePixelRatio, size().height() * devicePixelRatio); +} + void OsgWidget::dragEnterEvent(QDragEnterEvent* event) { LOG_INFO("OsgWidget::dragEnterEvent - Available formats:{}", event->mimeData()->formats().join(",").toStdString()); @@ -279,6 +288,11 @@ void OsgWidget::OnPresetModelDropped(const QString& modelType, const QString& mo height = 0.0; } + if (height < 0.0) + { + height = 0.0; + } + bool success = false; ModelInfo modelInfo = PresetModelConfigParser::Get().GetModelInfo(modelType, modelName, &success); if (!success) { diff --git a/src/viewer/OsgWidget.h b/src/viewer/OsgWidget.h index bb973ae4..2b5c8d75 100644 --- a/src/viewer/OsgWidget.h +++ b/src/viewer/OsgWidget.h @@ -28,6 +28,8 @@ protected: void resizeEvent(QResizeEvent* event) override; void paintEvent( QPaintEvent* /*event*/ ) override; + + virtual void showEvent(QShowEvent *event) override; // 拖拽事件处理 void dragEnterEvent(QDragEnterEvent* event) override;