Logo Search packages:      
Sourcecode: qt4-x11 version File versions

void QWidget::setParent ( QWidget parent,
Qt::WindowFlags  f 
) [inherited]

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts. This function also takes widget flags, f as an argument.

Definition at line 8460 of file qwidget.cpp.

References QWidget::clearFocus(), QWidget::create(), QWidget::focusWidget(), QWidget::hide(), QWidget::isAncestorOf(), QWidget::isEnabled(), QWidget::isWindow(), QWidget::parentWidget(), QCoreApplication::postEvent(), QCoreApplication::sendEvent(), QWidget::setAttribute(), QWidget::testAttribute(), QWidget::updatesEnabled, QWidget::window(), and QWidget::windowSurface().

{
    Q_D(QWidget);
    bool resized = testAttribute(Qt::WA_Resized);
    bool wasCreated = testAttribute(Qt::WA_WState_Created);
    QWidget *oldtlw = window();
    bool newParent = (parent != parentWidget()) || !wasCreated;

    if (wasCreated) {
        if (!testAttribute(Qt::WA_WState_Hidden)) {
            hide();
            setAttribute(Qt::WA_WState_ExplicitShowHide, false);
        }
        if (newParent) {
            QEvent e(QEvent::ParentAboutToChange);
            QApplication::sendEvent(this, &e);
        }
    }
    if (newParent && isAncestorOf(focusWidget()))
        focusWidget()->clearFocus();

    d->setParent_sys(parent, f);

#ifdef Q_BACKINGSTORE_SUBSURFACES
    QTLWExtra *extra = d->maybeTopData();
    QWindowSurface *windowSurface = (extra ? extra->windowSurface : 0);
    if (newParent && windowSurface) {
        QWidgetBackingStore *oldBs = oldtlw->d_func()->maybeBackingStore();
        if (oldBs)
            oldBs->subSurfaces.removeAll(windowSurface);

        if (parent) {
            QWidgetBackingStore *newBs = parent->d_func()->maybeBackingStore();
            if (newBs)
                newBs->subSurfaces.append(windowSurface);
        }
    }
#endif

#ifdef Q_WIDGET_USE_DIRTYLIST
    if (newParent) {
        QWidgetBackingStore *oldBs = oldtlw->d_func()->maybeBackingStore();
        if (oldBs)
            oldBs->removeDirtyWidget(this);
    }
#endif

    if ((QApplicationPrivate::app_compile_version < 0x040200
         || QApplicationPrivate::testAttribute(Qt::AA_ImmediateWidgetCreation))
        && !testAttribute(Qt::WA_WState_Created))
        create();

    d->reparentFocusWidgets(oldtlw);
    setAttribute(Qt::WA_Resized, resized);
    if (!testAttribute(Qt::WA_StyleSheet)
        && (!parent || !parent->testAttribute(Qt::WA_StyleSheet))) {
        d->resolveFont();
        d->resolvePalette();
    }
    d->resolveLayoutDirection();
    d->resolveLocale();

    if (QTLWExtra *extra = oldtlw->d_func()->maybeTopData())
        extra->sizeAdjusted = false;
    if (QTLWExtra *extra = window()->d_func()->maybeTopData())
        extra->sizeAdjusted = false;

    // Note: GL widgets under Windows will always need a ParentChange
    // event to handle recreation/rebinding of the GL context, hence
    // the (f & Qt::MSWindowsOwnDC) clause
    if (newParent
#ifdef Q_WS_WIN
        || (f & Qt::MSWindowsOwnDC)
#endif
        ) {
        // propagate enabled updates enabled state to non-windows
        if (!isWindow()) {
            if (!testAttribute(Qt::WA_ForceDisabled))
                d->setEnabled_helper(parent ? parent->isEnabled() : true);
            if (!testAttribute(Qt::WA_ForceUpdatesDisabled))
                d->setUpdatesEnabled_helper(parent ? parent->updatesEnabled() : true);
        }
        d->inheritStyle();

        // send and post remaining QObject events
        if (parent && d->sendChildEvents) {
            QChildEvent e(QEvent::ChildAdded, this);
            QApplication::sendEvent(parent, &e);
#ifdef QT3_SUPPORT
            if (parent->d_func()->pendingChildInsertedEvents.isEmpty()) {
                QApplication::postEvent(parent,
                                        new QEvent(QEvent::ChildInsertedRequest),
                                        Qt::HighEventPriority);
            }
            parent->d_func()->pendingChildInsertedEvents.append(this);
#endif
        }

//### already hidden above ---> must probably do something smart on the mac
// #ifdef Q_WS_MAC
//             extern bool qt_mac_is_macdrawer(const QWidget *); //qwidget_mac.cpp
//             if(!qt_mac_is_macdrawer(q)) //special case
//                 q->setAttribute(Qt::WA_WState_Hidden);
// #else
//             q->setAttribute(Qt::WA_WState_Hidden);
//#endif

        if (parent && d->sendChildEvents && d->polished) {
            QChildEvent e(QEvent::ChildPolished, this);
            QCoreApplication::sendEvent(parent, &e);
        }

        QEvent e(QEvent::ParentChange);
        QApplication::sendEvent(this, &e);
    }

    if (!wasCreated) {
        if (isWindow() || parentWidget()->isVisible())
            setAttribute(Qt::WA_WState_Hidden, true);
        else if (!testAttribute(Qt::WA_WState_ExplicitShowHide))
            setAttribute(Qt::WA_WState_Hidden, false);
    }

#ifndef QT_NO_GRAPHICSVIEW
    // Embed the widget into a proxy if the parent is embedded.
    // ### Doesn't handle reparenting out of an embedded widget.
    if (oldtlw->d_func()->graphicsProxyWidget()) {
        if (QGraphicsProxyWidget *ancestorProxy = d->nearestGraphicsProxyWidget(oldtlw))
            ancestorProxy->d_func()->unembedSubWindow(this);
    }
    if (isWindow() && parent && !d->graphicsProxyWidget()) {
        if (QGraphicsProxyWidget *ancestorProxy = d->nearestGraphicsProxyWidget(parent))
            ancestorProxy->d_func()->embedSubWindow(this);
    }
#endif
}


Generated by  Doxygen 1.6.0   Back to index