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

bool QWidget::event ( QEvent event  )  [protected, virtual, inherited]

This is the main event handler; it handles event event. You can reimplement this function in a subclass, but we recommend using one of the specialized event handlers instead.

Key press and release events are treated differently from other events. event() checks for Tab and Shift+Tab and tries to move the focus appropriately. If there is no widget to move the focus to (or the key press is not Tab or Shift+Tab), event() calls keyPressEvent().

Mouse and tablet event handling is also slightly special: only when the widget is enabled, event() will call the specialized handlers such as mousePressEvent(); otherwise it will discard the event.

This function returns true if the event was recognized, otherwise it returns false. If the recognized event was accepted (see QEvent::accepted), any further processing such as event propagation to the parent widget stops.

See also:
closeEvent(), focusInEvent(), focusOutEvent(), enterEvent(), keyPressEvent(), keyReleaseEvent(), leaveEvent(), mouseDoubleClickEvent(), mouseMoveEvent(), mousePressEvent(), mouseReleaseEvent(), moveEvent(), paintEvent(), resizeEvent(), QObject::event(), QObject::timerEvent()

Reimplemented from QObject.

Reimplemented in MyWidget, SortingBox, Phonon::VideoWidget, QWebView, QMessageBox, QWizard, QGraphicsView, QAbstractItemView, QHeaderView, QListView, QListWidget, QTableWidget, QTreeWidget, QX11EmbedWidget, QX11EmbedContainer, QAbstractButton, QAbstractScrollArea, QAbstractSlider, QAbstractSpinBox, QCalendarWidget, QCheckBox, QComboBox, QCommandLinkButton, QDateTimeEdit, QDial, QDialogButtonBox, QDockWidget, QFocusFrame, QFontComboBox, QFrame, QGroupBox, QLabel, QLCDNumber, QLineEdit, QMainWindow, QMdiArea, QMdiSubWindow, QMenu, QMenuBar, QPlainTextEdit, QProgressBar, QPushButton, QRadioButton, QRubberBand, QScrollArea, QScrollBar, QSizeGrip, QSlider, QSpinBox, QSplashScreen, QSplitter, QSplitterHandle, QStackedWidget, QStatusBar, QTabBar, QTabWidget, QTextBrowser, QTextEdit, QToolBar, QToolBox, QToolButton, QWorkspace, QGLWidget, Q3TextEdit, Q3ButtonGroup, Q3DateEdit, Q3TimeEdit, Q3DockWindow, Q3GroupBox, Q3MainWindow, Q3ToolBar, and Q3WidgetStack.

Definition at line 6872 of file qwidget.cpp.

References QEvent::accept(), QWidget::actionEvent(), QList< T >::at(), QWidget::changeEvent(), QAccessibleEvent::child(), QWidget::closeEvent(), QWidget::contextMenuEvent(), QWidget::customContextMenuRequested(), QWidget::dragEnterEvent(), QWidget::dragLeaveEvent(), QWidget::dragMoveEvent(), QWidget::dropEvent(), QWidget::ensurePolished(), QWidget::enterEvent(), QObject::event(), QMenu::exec(), QWidget::focusInEvent(), QWidget::focusNextPrevChild(), QWidget::focusOutEvent(), QApplication::font(), QWidget::hideEvent(), QEvent::ignore(), QWidget::inputMethodEvent(), QWidget::inputMethodQuery(), QEvent::isAccepted(), QPalette::isEqual(), QWidget::isHidden(), QWidget::isVisible(), QWidget::isWindow(), QKeyEvent::key(), QWidget::keyPressEvent(), QWidget::keyReleaseEvent(), QObject::killTimer(), QWidget::languageChange(), QWidget::leaveEvent(), QWidget::mapToGlobal(), QKeyEvent::modifiers(), QWidget::mouseDoubleClickEvent(), QWidget::mouseMoveEvent(), QWidget::mousePressEvent(), QWidget::mouseReleaseEvent(), QWidget::moveEvent(), QWidget::paintEvent(), QApplication::palette(), QStyle::polish(), QWidget::pos, QObject::qobject_cast(), QWidget::resetInputContext(), QWidget::resizeEvent(), QCoreApplication::sendEvent(), QCoreApplication::sendPostedEvents(), QWidget::setAttribute(), QAccessibleEvent::setValue(), QWidget::showEvent(), QToolTip::showText(), QWhatsThis::showText(), QList< T >::size(), QWidget::style(), QWidget::tabletEvent(), QWidget::testAttribute(), QObject::timerEvent(), QTimerEvent::timerId(), QEvent::type(), QWidget::update(), QWidget::wheelEvent(), QWidget::windowActivationChange(), and QWidget::windowType().

Referenced by QToolBar::event(), QMainWindow::event(), QAbstractButton::event(), QWebView::event(), QGLWidget::event(), QTabWidget::event(), QSplitterHandle::event(), QLineEdit::event(), QTabBar::event(), QGroupBox::event(), Phonon::VideoWidget::event(), Q3TimeEdit::event(), QWorkspace::event(), QSplitter::event(), Q3DateEdit::event(), QFocusFrame::event(), SortingBox::event(), QMessageBox::event(), QAbstractSlider::event(), QSizeGrip::event(), QMenuBar::event(), QDialogButtonBox::event(), QCalendarWidget::event(), QMenu::event(), QDockWidget::event(), QAbstractSpinBox::event(), QX11EmbedContainer::event(), Q3TextEdit::event(), QStatusBar::event(), QSplashScreen::event(), Q3MainWindow::event(), QRubberBand::event(), QMdiSubWindow::event(), QX11EmbedWidget::event(), QProgressBar::event(), QFrame::event(), QComboBox::event(), QWizard::event(), MyWidget::event(), and QWidget::setFocus().

{
    Q_D(QWidget);

    // ignore mouse events when disabled
    if (!isEnabled()) {
        switch(event->type()) {
        case QEvent::TabletPress:
        case QEvent::TabletRelease:
        case QEvent::TabletMove:
        case QEvent::MouseButtonPress:
        case QEvent::MouseButtonRelease:
        case QEvent::MouseButtonDblClick:
        case QEvent::MouseMove:
        case QEvent::ContextMenu:
#ifndef QT_NO_WHEELEVENT
        case QEvent::Wheel:
#endif
            return false;
        default:
            break;
        }
    }
    switch (event->type()) {
#ifdef Q_RATE_LIMIT_PAINTING
    case QEvent::Timer: {
        QTimerEvent *timerEvent = static_cast<QTimerEvent *>(event);
        if (timerEvent->timerId() == d->timerId) {
            killTimer(d->timerId);
            QWidgetBackingStore *bs = d->maybeBackingStore();
            if (bs)
                bs->updateDirtyRegion(this);
            d->timerId = -1;
        } else {
            this->timerEvent(timerEvent);
        }
        break;
    }
#endif
    case QEvent::MouseMove:
        mouseMoveEvent((QMouseEvent*)event);
        break;

    case QEvent::MouseButtonPress:
        // Don't reset input context here. Whether reset or not is
        // a responsibility of input method. reset() will be
        // called by mouseHandler() of input method if necessary
        // via mousePressEvent() of text widgets.
#if 0
        resetInputContext();
#endif
        mousePressEvent((QMouseEvent*)event);
        break;

    case QEvent::MouseButtonRelease:
        mouseReleaseEvent((QMouseEvent*)event);
        break;

    case QEvent::MouseButtonDblClick:
        mouseDoubleClickEvent((QMouseEvent*)event);
        break;
#ifndef QT_NO_WHEELEVENT
    case QEvent::Wheel:
        wheelEvent((QWheelEvent*)event);
        break;
#endif
#ifndef QT_NO_TABLETEVENT
    case QEvent::TabletMove:
    case QEvent::TabletPress:
    case QEvent::TabletRelease:
        tabletEvent((QTabletEvent*)event);
        break;
#endif
#ifdef QT3_SUPPORT
    case QEvent::Accel:
        event->ignore();
        return false;
#endif
    case QEvent::KeyPress: {
        QKeyEvent *k = (QKeyEvent *)event;
        bool res = false;
        if (!(k->modifiers() & (Qt::ControlModifier | Qt::AltModifier))) {  //### Add MetaModifier?
            if (k->key() == Qt::Key_Backtab
                || (k->key() == Qt::Key_Tab && (k->modifiers() & Qt::ShiftModifier)))
                res = focusNextPrevChild(false);
            else if (k->key() == Qt::Key_Tab)
                res = focusNextPrevChild(true);
            if (res)
                break;
        }
        keyPressEvent(k);
#ifdef QT_KEYPAD_NAVIGATION
        if (!k->isAccepted() && QApplication::keypadNavigationEnabled()
            && !(k->modifiers() & (Qt::ControlModifier | Qt::AltModifier | Qt::ShiftModifier))) {
            if (k->key() == Qt::Key_Up)
                res = focusNextPrevChild(false);
            else if (k->key() == Qt::Key_Down)
                res = focusNextPrevChild(true);
            if (res) {
                k->accept();
                break;
            }
        }
#endif
#ifndef QT_NO_WHATSTHIS
        if (!k->isAccepted()
            && k->modifiers() & Qt::ShiftModifier && k->key() == Qt::Key_F1
            && d->whatsThis.size()) {
            QWhatsThis::showText(mapToGlobal(inputMethodQuery(Qt::ImMicroFocus).toRect().center()), d->whatsThis, this);
            k->accept();
        }
#endif
    }
        break;

    case QEvent::KeyRelease:
        keyReleaseEvent((QKeyEvent*)event);
        // fall through
    case QEvent::ShortcutOverride:
        break;

    case QEvent::InputMethod:
        inputMethodEvent((QInputMethodEvent *) event);
        break;

    case QEvent::PolishRequest:
        ensurePolished();
        break;

    case QEvent::Polish: {
        style()->polish(this);
        setAttribute(Qt::WA_WState_Polished);
        if (!testAttribute(Qt::WA_SetFont) && !QApplication::font(this).isCopyOf(QApplication::font()))
            d->resolveFont();
        if (!QApplication::palette(this).isCopyOf(QApplication::palette()))
            d->resolvePalette();
#ifdef QT3_SUPPORT
        if(d->sendChildEvents)
            QApplication::sendPostedEvents(this, QEvent::ChildInserted);
#endif
    }
        break;

    case QEvent::ApplicationWindowIconChange:
        if (isWindow() && !testAttribute(Qt::WA_SetWindowIcon)) {
            d->setWindowIcon_sys();
            d->setWindowIcon_helper();
        }
        break;
    case QEvent::FocusIn:
#if defined(Q_WS_WIN)
        QWinInputContext::updateImeStatus(this, true);
#endif
        focusInEvent((QFocusEvent*)event);
        break;

    case QEvent::FocusOut:
#if defined(Q_WS_WIN)
        QWinInputContext::updateImeStatus(this, false);
#endif
        focusOutEvent((QFocusEvent*)event);
        break;

    case QEvent::Enter:
#ifndef QT_NO_STATUSTIP
        if (d->statusTip.size()) {
            QStatusTipEvent tip(d->statusTip);
            QApplication::sendEvent(const_cast<QWidget *>(this), &tip);
        }
#endif
        enterEvent(event);
        break;

    case QEvent::Leave:
#ifndef QT_NO_STATUSTIP
        if (d->statusTip.size()) {
            QString empty;
            QStatusTipEvent tip(empty);
            QApplication::sendEvent(const_cast<QWidget *>(this), &tip);
        }
#endif
        leaveEvent(event);
        break;

    case QEvent::HoverEnter:
    case QEvent::HoverLeave:
        update();
        break;

    case QEvent::Paint:
        // At this point the event has to be delivered, regardless
        // whether the widget isVisible() or not because it
        // already went through the filters
        paintEvent((QPaintEvent*)event);
        break;

    case QEvent::Move:
        moveEvent((QMoveEvent*)event);
        break;

    case QEvent::Resize:
        resizeEvent((QResizeEvent*)event);
        break;

    case QEvent::Close:
        closeEvent((QCloseEvent *)event);
        break;

    case QEvent::ContextMenu:
        switch (data->context_menu_policy) {
        case Qt::DefaultContextMenu:
            contextMenuEvent(static_cast<QContextMenuEvent *>(event));
            break;
        case Qt::CustomContextMenu:
            emit customContextMenuRequested(static_cast<QContextMenuEvent *>(event)->pos());
            break;
#ifndef QT_NO_MENU
        case Qt::ActionsContextMenu:
            if (d->actions.count()) {
                QMenu::exec(d->actions, static_cast<QContextMenuEvent *>(event)->globalPos());
                break;
            }
            // fall through
#endif
        case Qt::PreventContextMenu:
        default:
            event->ignore();
            break;
        }
        break;

#ifndef QT_NO_DRAGANDDROP
    case QEvent::Drop:
        dropEvent((QDropEvent*) event);
        break;

    case QEvent::DragEnter:
        dragEnterEvent((QDragEnterEvent*) event);
        break;

    case QEvent::DragMove:
        dragMoveEvent((QDragMoveEvent*) event);
        break;

    case QEvent::DragLeave:
        dragLeaveEvent((QDragLeaveEvent*) event);
        break;
#endif

    case QEvent::Show:
        showEvent((QShowEvent*) event);
        break;

    case QEvent::Hide:
        hideEvent((QHideEvent*) event);
        break;

    case QEvent::ShowWindowRequest:
        if (!isHidden())
            d->show_sys();
        break;

    case QEvent::ApplicationFontChange:
        d->resolveFont();
        break;
    case QEvent::ApplicationPaletteChange:
        if (!(windowType() == Qt::Desktop))
            d->resolvePalette();
        break;

    case QEvent::ToolBarChange:
    case QEvent::ActivationChange:
    case QEvent::EnabledChange:
    case QEvent::FontChange:
    case QEvent::StyleChange:
    case QEvent::PaletteChange:
    case QEvent::WindowTitleChange:
    case QEvent::IconTextChange:
    case QEvent::ModifiedChange:
    case QEvent::MouseTrackingChange:
    case QEvent::ParentChange:
    case QEvent::WindowStateChange:
    case QEvent::LocaleChange:
    case QEvent::MacSizeChange:
    case QEvent::ContentsRectChange:
        changeEvent(event);
        break;

    case QEvent::WindowActivate:
    case QEvent::WindowDeactivate: {
#ifdef QT3_SUPPORT
        windowActivationChange(event->type() != QEvent::WindowActivate);
#endif
        if (isVisible() && !palette().isEqual(QPalette::Active, QPalette::Inactive))
            update();
        QList<QObject*> childList = d->children;
        for (int i = 0; i < childList.size(); ++i) {
            QWidget *w = qobject_cast<QWidget *>(childList.at(i));
            if (w && w->isVisible() && !w->isWindow())
                QApplication::sendEvent(w, event);
        }
        break; }

    case QEvent::LanguageChange:
#ifdef QT3_SUPPORT
        languageChange();
#endif
        changeEvent(event);
        {
            QList<QObject*> childList = d->children;
            for (int i = 0; i < childList.size(); ++i) {
                QObject *o = childList.at(i);
                QApplication::sendEvent(o, event);
            }
        }
        update();
        break;

    case QEvent::ApplicationLayoutDirectionChange:
        d->resolveLayoutDirection();
        break;

    case QEvent::LayoutDirectionChange:
        if (d->layout)
            d->layout->invalidate();
        update();
        changeEvent(event);
        break;
#if defined(Q_WS_X11) || defined(Q_WS_QWS) || (defined(Q_WS_WIN) || defined(Q_WS_MAC))
    case QEvent::UpdateRequest: {
#ifdef Q_WS_MAC
        d->cleanWidget_sys(d->dirtyOnScreen);
        break;
#endif
#ifndef Q_WS_WIN
        extern void qt_syncBackingStore(QWidget *widget);
#endif
        qt_syncBackingStore(this);
        break; }
#endif

    case QEvent::UpdateLater:
        update(static_cast<QUpdateLaterEvent*>(event)->region());
        break;

    case QEvent::WindowBlocked:
    case QEvent::WindowUnblocked:
        {
            QList<QObject*> childList = d->children;
            for (int i = 0; i < childList.size(); ++i) {
                QObject *o = childList.at(i);
                if (o != qApp->activeModalWidget()) {
                    if (qobject_cast<QWidget *>(o) && static_cast<QWidget *>(o)->isWindow()) {
                        // do not forward the event to child windows,
                        // QApplication does this for us
                        continue;
                    }
                    QApplication::sendEvent(o, event);
                }
            }
        }
        break;
#ifndef QT_NO_TOOLTIP
    case QEvent::ToolTip:
        if (!d->toolTip.isEmpty())
            QToolTip::showText(static_cast<QHelpEvent*>(event)->globalPos(), d->toolTip, this);
        else
            event->ignore();
        break;
#endif
#ifndef QT_NO_WHATSTHIS
    case QEvent::WhatsThis:
        if (d->whatsThis.size())
            QWhatsThis::showText(static_cast<QHelpEvent *>(event)->globalPos(), d->whatsThis, this);
        else
            event->ignore();
        break;
    case QEvent::QueryWhatsThis:
        if (d->whatsThis.isEmpty())
            event->ignore();
        break;
#endif
#ifndef QT_NO_ACCESSIBILITY
    case QEvent::AccessibilityDescription:
    case QEvent::AccessibilityHelp: {
        QAccessibleEvent *ev = static_cast<QAccessibleEvent *>(event);
        if (ev->child())
            return false;
        switch (ev->type()) {
#ifndef QT_NO_TOOLTIP
        case QEvent::AccessibilityDescription:
            ev->setValue(d->toolTip);
            break;
#endif
#ifndef QT_NO_WHATSTHIS
        case QEvent::AccessibilityHelp:
            ev->setValue(d->whatsThis);
            break;
#endif
        default:
            return false;
        }
        break; }
#endif
    case QEvent::EmbeddingControl:
        d->topData()->frameStrut.setCoords(0 ,0, 0, 0);
        data->fstrut_dirty = false;
#if defined(Q_WS_WIN) || defined(Q_WS_X11)
        d->topData()->embedded = 1;
#endif
        break;
#ifndef QT_NO_ACTION
    case QEvent::ActionAdded:
    case QEvent::ActionRemoved:
    case QEvent::ActionChanged:
        actionEvent((QActionEvent*)event);
        break;
#endif

    case QEvent::KeyboardLayoutChange:
        {
            changeEvent(event);

            // inform children of the change
            QList<QObject*> childList = d->children;
            for (int i = 0; i < childList.size(); ++i) {
                QWidget *w = qobject_cast<QWidget *>(childList.at(i));
                if (w && w->isVisible() && !w->isWindow())
                    QApplication::sendEvent(w, event);
            }
            break;
        }
#ifdef Q_WS_MAC
    case QEvent::MacGLWindowChange:
        d->needWindowChange = false;
        break;
#endif
    default:
        return QObject::event(event);
    }
    return true;
}


Generated by  Doxygen 1.6.0   Back to index