Qt源代码阅读——QWidget::ShowNormal

showNormal

/*!q
    Restores the widget after it has been maximized or minimized.
    Calling this function only affects \l{isWindow()}{windows}.
    \sa setWindowState(), showMinimized(), showMaximized(), show(), hide(), isVisible()
*/
void QWidget::showNormal()
{
    ensurePolished();
    setWindowState(windowState() & ~(Qt::WindowMinimized
                                     | Qt::WindowMaximized
                                     | Qt::WindowFullScreen));
#if 0 // Used to be included in Qt4 for Q_WS_MAC
    // If the unified toolbar was enabled before going fullscreen, we have to enable it back.
    QMainWindow *mainWindow = qobject_cast<QMainWindow*>(this);
    if (mainWindow)
    {
        QMainWindowLayout *mainLayout = qobject_cast<QMainWindowLayout*>(mainWindow->layout());
        if (mainLayout->activateUnifiedToolbarAfterFullScreen) {
            mainWindow->setUnifiedTitleAndToolBarOnMac(true);
            mainLayout->activateUnifiedToolbarAfterFullScreen = false;
        }
    }
#endif
    setVisible(true);
}

/*!
    Ensures that the widget and its children have been polished by
    QStyle (i.e., have a proper font and palette).
    QWidget calls this function after it has been fully constructed
    but before it is shown the very first time. You can call this
    function if you want to ensure that the widget is polished before
    doing an operation, e.g., the correct font size might be needed in
    the widget's sizeHint() reimplementation. Note that this function
    \e is called from the default implementation of sizeHint().
    Polishing is useful for final initialization that must happen after
    all constructors (from base classes as well as from subclasses)
    have been called.
    If you need to change some settings when a widget is polished,
    reimplement event() and handle the QEvent::Polish event type.
    \b{Note:} The function is declred const so that it can be called from
    other const functions (e.g., sizeHint()).
    \sa event()
*/
void QWidget::ensurePolished() const
{
    Q_D(const QWidget);
    const QMetaObject *m = metaObject();
    if (m == d->polished)
        return;
    d->polished = m;
    QEvent e(QEvent::Polish);
    QCoreApplication::sendEvent(const_cast<QWidget *>(this), &e);
    // polish children after 'this'
    QList<QObject*> children = d->children;
    for (int i = 0; i < children.size(); ++i) {
        QObject *o = children.at(i);
        if(!o->isWidgetType())
            continue;
        if (QWidget *w = qobject_cast<QWidget *>(o))
            w->ensurePolished();
    }
    if (d->parent && d->sendChildEvents) {
        QChildEvent e(QEvent::ChildPolished, const_cast<QWidget *>(this));
        QCoreApplication::sendEvent(d->parent, &e);
    }
}

posted @ 2022-02-18 10:32  nino4love  阅读(686)  评论(0编辑  收藏  举报