diff options
author | Oliver Wolff <oliver.wolff@qt.io> | 2023-04-03 09:04:48 +0200 |
---|---|---|
committer | Oliver Wolff <oliver.wolff@qt.io> | 2023-04-06 10:36:08 +0200 |
commit | e7b67edeefcf01a7155c8b6adeffb1304d4d22e4 (patch) | |
tree | c62ddcea9806808171e7eb9cf49560d190de7d2f /tests/manual/hierarchy/objects.cpp | |
parent | 2ee58af673cc26b2a05feb1041217bb8c334d130 (diff) | |
download | qtactiveqt-e7b67edeefcf01a7155c8b6adeffb1304d4d22e4.tar.gz |
examples: Remove hierarchy example
Functionality is also covered in other examples so that hierarchy is no
longer needed.
In order to keep the use case's code in source, the example was moved to
tests/manual.
Pick-to: 6.5
Change-Id: I6b3e46d402877b93cfa4dc555328e1e115ec4fc6
Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io>
Diffstat (limited to 'tests/manual/hierarchy/objects.cpp')
-rw-r--r-- | tests/manual/hierarchy/objects.cpp | 70 |
1 files changed, 70 insertions, 0 deletions
diff --git a/tests/manual/hierarchy/objects.cpp b/tests/manual/hierarchy/objects.cpp new file mode 100644 index 0000000..6dfda44 --- /dev/null +++ b/tests/manual/hierarchy/objects.cpp @@ -0,0 +1,70 @@ +// Copyright (C) 2015 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause + +#include "objects.h" +#include <QLayout> +#include <QPainter> + +/* Implementation of QParentWidget */ +//! [0] +QParentWidget::QParentWidget(QWidget *parent) +: QWidget(parent), + m_vbox(new QVBoxLayout(this)) +{ +} + +//! [0] //! [1] +void QParentWidget::createSubWidget(const QString &name) +{ + QSubWidget *sw = new QSubWidget(this, name); + m_vbox->addWidget(sw); + sw->setLabel(name); + sw->show(); +} + +//! [1] //! [2] +QSubWidget *QParentWidget::subWidget(const QString &name) +{ + return findChild<QSubWidget *>(name); +} + +//! [2] +QSize QParentWidget::sizeHint() const +{ + return QWidget::sizeHint().expandedTo(QSize(100, 100)); +} + +/* Implementation of QSubWidget */ +//! [3] +QSubWidget::QSubWidget(QWidget *parent, const QString &name) +: QWidget(parent) +{ + setObjectName(name); +} + +void QSubWidget::setLabel(const QString &text) +{ + m_label = text; + setObjectName(text); + update(); +} + +QString QSubWidget::label() const +{ + return m_label; +} + +QSize QSubWidget::sizeHint() const +{ + QFontMetrics fm(font()); + return QSize(fm.horizontalAdvance(m_label), fm.height()); +} + +void QSubWidget::paintEvent(QPaintEvent *) +{ + QPainter painter(this); + painter.setPen(palette().text().color()); + painter.drawText(rect(), Qt::AlignCenter, m_label); +//! [3] //! [4] +} +//! [4] |