Home · All Namespaces · All Classes · Main Classes · Grouped Classes · Modules · Functions

objects.cpp Example File
activeqt/hierarchy/objects.cpp

 /****************************************************************************
 **
 ** Copyright (C) 2008 Nokia Corporation and/or its subsidiary(-ies).
 ** Contact: Qt Software Information (qt-info@nokia.com)
 **
 ** This file is part of the example classes of the Qt Toolkit.
 **
 ** Commercial Usage
 ** Licensees holding valid Qt Commercial licenses may use this file in
 ** accordance with the Qt Commercial License Agreement provided with the
 ** Software or, alternatively, in accordance with the terms contained in
 ** a written agreement between you and Nokia.
 **
 **
 ** If you are unsure which license is appropriate for your use, please
 ** contact the sales department at qt-sales@nokia.com.
 **
 ****************************************************************************/

 #include "objects.h"
 #include <QLayout>
 #include <QPainter>

 /* Implementation of QParentWidget */
 QParentWidget::QParentWidget(QWidget *parent)
 : QWidget(parent)
 {
     vbox = new QVBoxLayout(this);
 }

 void QParentWidget::createSubWidget(const QString &name)
 {
     QSubWidget *sw = new QSubWidget(this, name);
     vbox->addWidget(sw);
     sw->setLabel(name);
     sw->show();
 }

 QSubWidget *QParentWidget::subWidget(const QString &name)
 {
     return qFindChild<QSubWidget*>(this, name);
 }

 QSize QParentWidget::sizeHint() const
 {
     return QWidget::sizeHint().expandedTo(QSize(100, 100));
 }

 /* Implementation of QSubWidget */
 QSubWidget::QSubWidget(QWidget *parent, const QString &name)
 : QWidget(parent)
 {
     setObjectName(name);
 }

 void QSubWidget::setLabel(const QString &text)
 {
     lbl = text;
     setObjectName(text);
     update();
 }

 QString QSubWidget::label() const
 {
     return lbl;
 }

 QSize QSubWidget::sizeHint() const
 {
     QFontMetrics fm(font());
     return QSize(fm.width(lbl), fm.height());
 }

 void QSubWidget::paintEvent(QPaintEvent *)
 {
     QPainter painter(this);
     painter.setPen(palette().text().color());
     painter.drawText(rect(), Qt::AlignCenter, lbl);
 }


Copyright © 2008 Nokia Trademarks
Qt 4.4.3