Repository navigation
Description
Description with steps to reproduce
When using QtNodes::GraphicsView with a QOpenGLWidget viewport inside the Advanced Docking System (ADS) tabbed layout (Dock-in-Dock), two severe rendering and layout issues occur when switching between tabs:
-
The Black Screen Bug (Context/FBO Loss): When
QApplication::setAttribute(Qt::AA_ShareOpenGLContexts)is enabled (which is mandatory to preventQOpenGLShader::link: Duplicate function maincrashes in multi-dock environments), switching tabs causes theQGraphicsViewto render completely black. The underlying OpenGL Framebuffer Object (FBO) seems to be discarded by Qt and is not properly rebuilt when the tab is shown again. -
The Auto-Centering / Coordinate Loss Bug: When ADS hides/shows or rearranges dock tabs, its layout engine dynamically squashes the widget's size (sometimes down to
0x0temporarily). This extreme resize triggersQGraphicsView's internal scrollbar recalculation. Consequently, the user's pan/zoom coordinates are permanently lost, and the canvas violently auto-centers or jumps to a random offset every time the user switches tabs.
Environment
- OS: Windows 10/11
- Qt Version: 6.5.2
- Compiler: MSVC (or MinGW)
- NodeEditor Version: 3.0.16
- ADS Version: 5.0.0
Steps to reproduce
- Compile and run the single-file Minimal Reproducible Example (MRE) provided below.
- The app opens with 3 tabs ("Project 1, 2, 3").
- To see the Coordinate Bug: In Tab 1, right-click and pan the text to the extreme bottom-right corner. Switch to Tab 2, then back to Tab 1. Notice the canvas has violently reset/centered itself.
- To see the Black Screen Bug: Vigorously switch between the tabs or maximize/minimize the main window. Notice the viewports become completely black, and the scene stops rendering.
Minimal Reproducible Example (MRE)
Here is a single-file main.cpp that 100% reproduces both issues out of the box.
Supporting files, videos and screenshots
#include <QApplication>
#include <QMainWindow>
#include <QWidget>
#include <QVBoxLayout>
#include <QOpenGLWidget>
#include <QSurfaceFormat>
#include <AdvancedDocking/DockManager.h>
#include <AdvancedDocking/DockWidget.h>
#include <AdvancedDocking/DockAreaWidget.h>
#include <QtNodes/DataFlowGraphModel>
#include <QtNodes/DataFlowGraphicsScene>
#include <QtNodes/GraphicsView>
#include <QtNodes/NodeDelegateModelRegistry>
class NodeEditorTestWidget : public QWidget {
public:
NodeEditorTestWidget(const QString& title, std::shared_ptr<QtNodes::NodeDelegateModelRegistry> registry, QWidget* parent = nullptr)
: QWidget(parent)
{
auto* layout = new QVBoxLayout(this);
layout->setContentsMargins(0, 0, 0, 0);
m_graphModel = std::make_shared<QtNodes::DataFlowGraphModel>(registry);
m_scene = new QtNodes::DataFlowGraphicsScene(*m_graphModel, this);
m_view = new QtNodes::GraphicsView(m_scene, this);
// Setup OpenGL Viewport
m_view->setViewport(new QOpenGLWidget());
m_view->setViewportUpdateMode(QGraphicsView::FullViewportUpdate);
m_view->setCacheMode(QGraphicsView::CacheNone);
layout->addWidget(m_view);
auto* text = m_scene->addText(title + "\n(Pan me to the corner, then switch tabs!)");
text->setDefaultTextColor(Qt::white);
text->setPos(0, 0);
}
private:
std::shared_ptr<QtNodes::DataFlowGraphModel> m_graphModel;
QtNodes::DataFlowGraphicsScene* m_scene = nullptr;
QtNodes::GraphicsView* m_view = nullptr;
};
class MainWindow : public QMainWindow {
public:
MainWindow(QWidget* parent = nullptr) : QMainWindow(parent) {
setWindowTitle("ADS + QtNodes + QOpenGLWidget Bug MRE");
resize(1280, 800);
m_registry = std::make_shared<QtNodes::NodeDelegateModelRegistry>();
m_outerDockManager = new ads::CDockManager(this);
QWidget* innerContainer = new QWidget();
auto* innerLayout = new QVBoxLayout(innerContainer);
innerLayout->setContentsMargins(0, 0, 0, 0);
m_innerDockManager = new ads::CDockManager(innerContainer);
innerLayout->addWidget(m_innerDockManager);
ads::CDockWidget* centralEditorDock = new ads::CDockWidget("Editor Workspace");
centralEditorDock->setObjectName("CentralEditorWorkspace");
centralEditorDock->setWidget(innerContainer);
centralEditorDock->setFeature(ads::CDockWidget::DockWidgetClosable, false);
centralEditorDock->setFeature(ads::CDockWidget::DockWidgetMovable, false);
centralEditorDock->setFeature(ads::CDockWidget::DockWidgetFloatable, false);
m_outerDockManager->setCentralWidget(centralEditorDock);
addNodeDock("Project 1");
addNodeDock("Project 2");
addNodeDock("Project 3");
}
private:
void addNodeDock(const QString& title) {
auto* editorWidget = new NodeEditorTestWidget(title, m_registry);
auto* dock = new ads::CDockWidget(title);
dock->setWidget(editorWidget);
dock->setFeature(ads::CDockWidget::DockWidgetClosable, true);
if (auto center = m_innerDockManager->dockArea(0)) {
m_innerDockManager->addDockWidget(ads::CenterDockWidgetArea, dock, center);
} else {
m_innerDockManager->addDockWidget(ads::CenterDockWidgetArea, dock);
}
}
ads::CDockManager* m_outerDockManager;
ads::CDockManager* m_innerDockManager;
std::shared_ptr<QtNodes::NodeDelegateModelRegistry> m_registry;
};
int main(int argc, char* argv[]) {
// CRITICAL: Triggers the FBO loss issue when switching tabs
QApplication::setAttribute(Qt::AA_ShareOpenGLContexts);
QSurfaceFormat format;
format.setProfile(QSurfaceFormat::CompatibilityProfile);
format.setDepthBufferSize(24);
format.setStencilBufferSize(8);
format.setSamples(4);
format.setSwapBehavior(QSurfaceFormat::DoubleBuffer);
QSurfaceFormat::setDefaultFormat(format);
QApplication a(argc, argv);
MainWindow w;
w.show();
return a.exec();
}Qt Version
QT6.5.2
Operating system
Windows11
Additional context
No response
Checklist
- I have verified that this issue has not been logged before, by searching the issue tracker for similar issues
- I have attached all requested files and information to this report
- I have attempted to identify the root problem as concisely as possible, and have used minimal reproducible examples where possible
Activity
z1485671578 commentedon Jul 10, 2026
After diving into the rendering pipeline and the source code, I found the root causes and created non-intrusive workarounds via subclassing. I am sharing them here for anyone facing the same integration issues, and to suggest potential improvements for
QtNodes.1. The Auto-Centering Issue
Cause: In
QtNodes::GraphicsView,showEvent(QShowEvent *event)seems to explicitly callcenterScene()(or similar logic). In a dynamic docking environment like ADS, hiding/showing widgets is extremely frequent. Forcing a center alignment on everyshowEventmakes it impossible to maintain the user's viewport coordinates.My Workaround:
I derived a new class to bypass the
QtNodes::GraphicsView::showEventand call the baseQGraphicsView::showEventdirectly. This perfectly preserves the coordinates during tab switches.Suggestion for QtNodes: Could we make the centerScene() behavior inside showEvent optional? Perhaps a boolean flag (e.g., setCenterOnShow(bool)) so developers using MDI or docking frameworks can disable it?
2. The Black Screen (FBO Loss) Issue
Cause: When ADS moves or hides the layout, it triggers cleanup routines in Qt's OpenGL backend. When the widget is shown again, the Framebuffer Object (FBO) is in a "zombie" state (it exists, but isn't properly bound to the surface), resulting in a black screen. viewport()->update() does not fix this.
My Workaround:
I created a custom QOpenGLWidget viewport that forces Qt to rebuild the FBO by faking a QResizeEvent when the widget is shown.
(Usage: m_view->setViewport(new GlViewport());)