diff options
author | Friedemann Kleint <Friedemann.Kleint@qt.io> | 2023-02-24 15:27:28 +0100 |
---|---|---|
committer | Friedemann Kleint <Friedemann.Kleint@qt.io> | 2023-02-28 11:36:50 +0100 |
commit | 5f31212791b4a044e2a0b62bb66b7d07c2494402 (patch) | |
tree | 90f9465f70acafb763e3c83c9d8022f3fbbbaca0 /examples | |
parent | 9c7c6e657ab848f5c252aa780a18e58ead3ee2f8 (diff) |
graphgallery example: Create the window containers with a parent
This avoids the QWindow being created as a top level window with a frame.
Pick-to: 6.5
Task-number: QTBUG-110698
Change-Id: I0a1116f833dd61c43a113c0e7a74a5181c1ee9b9
Reviewed-by: Cristian Maureira-Fredes <cristian.maureira-fredes@qt.io>
Reviewed-by: Leena Miettinen <riitta-leena.miettinen@qt.io>
Diffstat (limited to 'examples')
4 files changed, 24 insertions, 30 deletions
diff --git a/examples/datavisualization/graphgallery/bargraph.cpp b/examples/datavisualization/graphgallery/bargraph.cpp index bdbd03a2..fcef6286 100644 --- a/examples/datavisualization/graphgallery/bargraph.cpp +++ b/examples/datavisualization/graphgallery/bargraph.cpp @@ -21,14 +21,10 @@ BarGraph::BarGraph() { //! [0] m_barsGraph = new Q3DBars(); - m_container = QWidget::createWindowContainer(m_barsGraph); //! [0] } -BarGraph::~BarGraph() -{ - delete m_container; -} +BarGraph::~BarGraph() = default; bool BarGraph::initialize() { @@ -39,17 +35,18 @@ bool BarGraph::initialize() return false; } + //! [1] + m_barsWidget = new QWidget; + QHBoxLayout *hLayout = new QHBoxLayout(m_barsWidget); + m_container = QWidget::createWindowContainer(m_barsGraph, m_barsWidget); QSize screenSize = m_barsGraph->screen()->size(); m_container->setMinimumSize(QSize(screenSize.width() / 2, screenSize.height() / 1.75)); m_container->setMaximumSize(screenSize); m_container->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding); m_container->setFocusPolicy(Qt::StrongFocus); + hLayout->addWidget(m_container, 1); - //! [1] - m_barsWidget = new QWidget; - QHBoxLayout *hLayout = new QHBoxLayout(m_barsWidget); QVBoxLayout *vLayout = new QVBoxLayout(); - hLayout->addWidget(m_container, 1); hLayout->addLayout(vLayout); //! [1] diff --git a/examples/datavisualization/graphgallery/doc/src/graphgallery.qdoc b/examples/datavisualization/graphgallery/doc/src/graphgallery.qdoc index aca8c1a7..c4fdd854 100644 --- a/examples/datavisualization/graphgallery/doc/src/graphgallery.qdoc +++ b/examples/datavisualization/graphgallery/doc/src/graphgallery.qdoc @@ -34,15 +34,18 @@ \section2 Creating the Application - First, in \c{bargraph.cpp}, instantiate Q3DBars and a window container for it: + First, in \c{bargraph.cpp}, instantiate Q3DBars: \snippet graphgallery/bargraph.cpp 0 - The call to QWidget::createWindowContainer is required, as all data visualization graph classes - (Q3DBars, Q3DScatter, Q3DSurface) inherit QWindow. This is the only way to use a class that - inherits QWindow as a widget. + Then, create the widget, and horizontal and vertical layouts. - Then, create horizontal and vertical layouts. Add the graph and the vertical layout to the + The graph is embedded in a window container using + QWidget::createWindowContainer(). This is required because all data + visualization graph classes (Q3DBars, Q3DScatter, Q3DSurface) inherit + QWindow. This is the only way to use a class inheriting QWindow as a widget. + + Add the graph and the vertical layout to the horizontal one: \snippet graphgallery/bargraph.cpp 1 diff --git a/examples/datavisualization/graphgallery/scattergraph.cpp b/examples/datavisualization/graphgallery/scattergraph.cpp index baab4663..cbcc082b 100644 --- a/examples/datavisualization/graphgallery/scattergraph.cpp +++ b/examples/datavisualization/graphgallery/scattergraph.cpp @@ -16,13 +16,9 @@ using namespace Qt::StringLiterals; ScatterGraph::ScatterGraph() { m_scatterGraph = new Q3DScatter(); - m_container = QWidget::createWindowContainer(m_scatterGraph); } -ScatterGraph::~ScatterGraph() -{ - delete m_container; -} +ScatterGraph::~ScatterGraph() = default; bool ScatterGraph::initialize() { @@ -33,16 +29,17 @@ bool ScatterGraph::initialize() return -1; } + m_scatterWidget = new QWidget; + QHBoxLayout *hLayout = new QHBoxLayout(m_scatterWidget); + m_container = QWidget::createWindowContainer(m_scatterGraph, m_scatterWidget); QSize screenSize = m_scatterGraph->screen()->size(); m_container->setMinimumSize(QSize(screenSize.width() / 2, screenSize.height() / 1.75)); m_container->setMaximumSize(screenSize); m_container->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding); m_container->setFocusPolicy(Qt::StrongFocus); + hLayout->addWidget(m_container, 1); - m_scatterWidget = new QWidget; - QHBoxLayout *hLayout = new QHBoxLayout(m_scatterWidget); QVBoxLayout *vLayout = new QVBoxLayout(); - hLayout->addWidget(m_container, 1); hLayout->addLayout(vLayout); QCommandLinkButton *cameraButton = new QCommandLinkButton(m_scatterWidget); diff --git a/examples/datavisualization/graphgallery/surfacegraph.cpp b/examples/datavisualization/graphgallery/surfacegraph.cpp index 6caf49e1..b7cc0425 100644 --- a/examples/datavisualization/graphgallery/surfacegraph.cpp +++ b/examples/datavisualization/graphgallery/surfacegraph.cpp @@ -19,13 +19,9 @@ using namespace Qt::StringLiterals; SurfaceGraph::SurfaceGraph() { m_surfaceGraph = new Q3DSurface(); - m_container = QWidget::createWindowContainer(m_surfaceGraph); } -SurfaceGraph::~SurfaceGraph() -{ - delete m_container; -} +SurfaceGraph::~SurfaceGraph() = default; bool SurfaceGraph::initialize() { @@ -36,16 +32,17 @@ bool SurfaceGraph::initialize() return -1; } + m_surfaceWidget = new QWidget; + QHBoxLayout *hLayout = new QHBoxLayout(m_surfaceWidget); + m_container = QWidget::createWindowContainer(m_surfaceGraph, m_surfaceWidget); QSize screenSize = m_surfaceGraph->screen()->size(); m_container->setMinimumSize(QSize(screenSize.width() / 2, screenSize.height() / 1.75)); m_container->setMaximumSize(screenSize); m_container->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding); m_container->setFocusPolicy(Qt::StrongFocus); + hLayout->addWidget(m_container, 1); - m_surfaceWidget = new QWidget; - QHBoxLayout *hLayout = new QHBoxLayout(m_surfaceWidget); QVBoxLayout *vLayout = new QVBoxLayout(); - hLayout->addWidget(m_container, 1); hLayout->addLayout(vLayout); vLayout->setAlignment(Qt::AlignTop); |