objects.cpp Example File
activeqt/hierarchy/objects.cpp
#include "objects.h"
#include <QLayout>
#include <QPainter>
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));
}
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 Corporation and/or its subsidiary(-ies) |
Trademarks |
Qt 4.4.3 |