我是靠谱客的博主 哭泣小馒头,这篇文章主要介绍Qt 之 QChildEvent::child方法QChildEventDemo1: childEvent一个纯净的网站,现在分享给大家,希望可以做个参考。

QChildEvent

Child events are sent immediately to objects when children are added or removed.

Demo1: childEvent

开发者ID:KDE,项目名称:tupi,代码行数:29,代码来源:tvhbox.cpp

void KoVBox::childEvent(QChildEvent *event)
{
    switch (event->type()) {
    case QEvent::ChildAdded: {
        QChildEvent *childEvent = static_cast<QChildEvent *>(event);
        if (childEvent->child()->isWidgetType()) {
            QWidget *widget = static_cast<QWidget *>(childEvent->child());
            static_cast<QBoxLayout *>(layout())->addWidget(widget);
        }
        break;
    }
    case QEvent::ChildRemoved: {
        QChildEvent *childEvent = static_cast<QChildEvent *>(event);
        if (childEvent->child()->isWidgetType()) {
            QWidget *widget = static_cast<QWidget *>(childEvent->child());
            static_cast<QBoxLayout *>(layout())->removeWidget(widget);
        }
        break;
    }
    default:
        break;
    }
    QFrame::childEvent(event);
}

Demo2:event

开发者ID:BackupTheBerlios,项目名称:sim-im-svn,代码行数:29,代码来源:zodiak.cpp

bool TVHBox::event(QEvent* ev)
{
    switch (ev->type()) {
        case QEvent::ChildAdded:
        {
            QChildEvent* childEv = static_cast<QChildEvent *>(ev);

            if (childEv->child()->isWidgetType()) {
                QWidget* w = static_cast<QWidget *>(childEv->child());
                static_cast<QBoxLayout *>(layout())->addWidget(w);
            }

            return QWidget::event(ev);
        }
        case QEvent::ChildRemoved:
        {
            QChildEvent* childEv = static_cast<QChildEvent *>(ev);

            if (childEv->child()->isWidgetType()) {
                QWidget* w = static_cast<QWidget *>(childEv->child());
                static_cast<QBoxLayout *>(layout())->removeWidget(w);
            }

            return QWidget::event(ev);
        }
        default:
            return QWidget::event(ev);
    }
}

一个纯净的网站

https://vimsky.com/examples/

最后

以上就是哭泣小馒头最近收集整理的关于Qt 之 QChildEvent::child方法QChildEventDemo1: childEvent一个纯净的网站的全部内容,更多相关Qt内容请搜索靠谱客的其他文章。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(104)

评论列表共有 0 条评论

立即
投稿
返回
顶部