qboxlayout与qt布局(三)

来源:互联网 发布:c语言 __函数 编辑:程序博客网 时间:2024/06/05 08:01

     呃,,,记性总是不大好。每次找Qlayout的入口点时都要重新断点,真是的。好吧,把一些东西记一下下的。
QLayout是在哪里开始影响使用它的控件的呢?
    其实,是这样的,
    首先Qt的消息都是要经过 QApplication::notify()预先处理的,而对于 QApplication::notify()未处理的消息,就会通过调用QApplicationPrivate::notify_helper()来把消息发送到接收者那里去的。不过,在QApplicationPrivate::notify_helper()发消息到接收者那里去之前,它是会尝试调用一下下QLayout的widgetEvent()函数的,这样,就会跑到QLayout里面去,结果是QLayout把放在它里面的控件的size一一重新计算一遍的。代码如下:
bool QApplicationPrivate::notify_helper(QObject *receiver, QEvent * e)
{
    // send to all application event filters
    if (sendThroughApplicationEventFilters(receiver, e))
        return true;


    if (receiver->isWidgetType()) {
        QWidget *widget = static_cast<QWidget *>(receiver);


#if !defined(Q_WS_WINCE) || (defined(GWES_ICONCURS) && !defined(QT_NO_CURSOR))
        // toggle HasMouse widget state on enter and leave
        if ((e->type() == QEvent::Enter || e->type() == QEvent::DragEnter) &&
            (!QApplication::activePopupWidget() || QApplication::activePopupWidget() == widget->window()))
            widget->setAttribute(Qt::WA_UnderMouse, true);
        else if (e->type() == QEvent::Leave || e->type() == QEvent::DragLeave)
            widget->setAttribute(Qt::WA_UnderMouse, false);
#endif

        // 嗯,就是这个入口啦~
        if (QLayout *layout=widget->d_func()->layout) {
            layout->widgetEvent(e);

        }
    }


    // send to all receiver event filters
    if (sendThroughObjectEventFilters(receiver, e))
        return true;


    // deliver the event
    bool consumed = receiver->event(e);
    e->spont = false;
    return consumed;
}

原创粉丝点击