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

void QWidget::setAttribute ( Qt::WidgetAttribute  attribute,
bool  on = true 
) [inherited]

Sets the attribute attribute on this widget if on is true; otherwise clears the attribute.

See also:
testAttribute()

Definition at line 9120 of file qwidget.cpp.

References QWidget::clearFocus(), QWidget::createWinId(), QInputContext::focusWidget(), QWidget::internalWinId(), QWidget::isWindow(), QWidget::parentWidget(), QObject::qobject_cast(), QInputContext::reset(), QCoreApplication::sendEvent(), QWidget::setAttribute(), QWidget::setFocus(), QInputContext::setFocusWidget(), QWidget::style(), QWidget::testAttribute(), and QWidget::window().

Referenced by QMenu::actionEvent(), QLayout::addChildWidget(), QMdiArea::addSubWindow(), QGroupBox::childEvent(), Q3Table::contentsMouseReleaseEvent(), QAbstractFormBuilder::create(), QWidget::create(), MainWindow::createUndoView(), QWidget::destroy(), QAbstractButton::event(), QWidget::event(), QLabel::event(), QMdiSubWindow::event(), QSizeGrip::eventFilter(), QDialog::exec(), QWidget::grabShortcut(), Q3ListView::handleSizeChange(), QColumnView::initializeColumn(), QCalendarWidget::mousePressEvent(), QMenu::mousePressEvent(), QApplication::notify(), PictureFlow::PictureFlow(), QWindowsVistaStyle::polish(), QPlastiqueStyle::polish(), NorwegianWoodStyle::polish(), QCleanlooksStyle::polish(), QWindowsXPStyle::polish(), QMenu::popup(), Q3Frame::Q3Frame(), Q3ListBox::Q3ListBox(), QFocusFrame::QFocusFrame(), QGLWidget::QGLWidget(), QGraphicsView::QGraphicsView(), QListView::QListView(), QMdiSubWindow::QMdiSubWindow(), QRubberBand::QRubberBand(), QWebView::QWebView(), QX11EmbedContainer::QX11EmbedContainer(), QX11EmbedWidget::QX11EmbedWidget(), ScribbleArea::ScribbleArea(), QWidget::setAttribute(), QWidget::setContentsMargins(), Q3GroupBox::setFrameStyle(), QFrame::setFrameStyle(), QComboBox::setLineEdit(), QWidget::setMaximumSize(), QWidget::setMinimumSize(), QWidget::setParent(), QWidget::setStyle(), Q3MainWindow::setVisible(), QDialog::setVisible(), QMdiSubWindow::setWidget(), QWidget::setWindowState(), QDialog::showEvent(), SortingBox::SortingBox(), Q3DockWindow::undock(), QWindowsVistaStyle::unpolish(), QPlastiqueStyle::unpolish(), QWindowsXPStyle::unpolish(), QCleanlooksStyle::unpolish(), NorwegianWoodStyle::unpolish(), and QWidget::winId().

{
    if (testAttribute(attribute) == on)
        return;

    Q_D(QWidget);
    Q_ASSERT_X(sizeof(d->high_attributes)*8 >= (Qt::WA_AttributeCount - sizeof(uint)*8),
               "QWidget::setAttribute(WidgetAttribute, bool)",
               "QWidgetPrivate::high_attributes[] too small to contain all attributes in WidgetAttribute");
    if (attribute < int(8*sizeof(uint))) {
        if (on)
            data->widget_attributes |= (1<<attribute);
        else
            data->widget_attributes &= ~(1<<attribute);
    } else {
        const int x = attribute - 8*sizeof(uint);
        const int int_off = x / (8*sizeof(uint));
        if (on)
            d->high_attributes[int_off] |= (1<<(x-(int_off*8*sizeof(uint))));
        else
            d->high_attributes[int_off] &= ~(1<<(x-(int_off*8*sizeof(uint))));
    }

    switch (attribute) {

#ifndef QT_NO_DRAGANDDROP
    case Qt::WA_AcceptDrops:  {
        if (on && !testAttribute(Qt::WA_DropSiteRegistered))
            setAttribute(Qt::WA_DropSiteRegistered, true);
        else if (!on && (isWindow() || !parentWidget() || !parentWidget()->testAttribute(Qt::WA_DropSiteRegistered)))
            setAttribute(Qt::WA_DropSiteRegistered, false);
        QEvent e(QEvent::AcceptDropsChange);
        QApplication::sendEvent(this, &e);
        break;
    }
    case Qt::WA_DropSiteRegistered:  {
        d->registerDropSite(on);
        for (int i = 0; i < d->children.size(); ++i) {
            QWidget *w = qobject_cast<QWidget *>(d->children.at(i));
            if (w && !w->isWindow() && !w->testAttribute(Qt::WA_AcceptDrops) && w->testAttribute(Qt::WA_DropSiteRegistered) != on)
                w->setAttribute(Qt::WA_DropSiteRegistered, on);
        }
        break;
    }
#endif

    case Qt::WA_NoChildEventsForParent:
        d->sendChildEvents = !on;
        break;
    case Qt::WA_NoChildEventsFromChildren:
        d->receiveChildEvents = !on;
        break;
    case Qt::WA_MacBrushedMetal:
#ifdef Q_WS_MAC
        d->setStyle_helper(style(), false, true);  // Make sure things get unpolished/polished correctly.
        // fall through since changing the metal attribute affects the opaque size grip.
    case Qt::WA_MacOpaqueSizeGrip:
        d->macUpdateOpaqueSizeGrip();
        break;
    case Qt::WA_MacShowFocusRect:
        if (hasFocus()) {
            clearFocus();
            setFocus();
        }
        break;
#endif
    case Qt::WA_MacAlwaysShowToolWindow:
#ifdef Q_WS_MAC
        d->macUpdateHideOnSuspend();
#endif
        break;
    case Qt::WA_MacNormalSize:
    case Qt::WA_MacSmallSize:
    case Qt::WA_MacMiniSize:
#ifdef Q_WS_MAC
        d->macUpdateSizeAttribute();
#endif
        break;
    case Qt::WA_ShowModal:
        if (!on) {
            if (isVisible())
                QApplicationPrivate::leaveModal(this);
            // reset modality type to Modeless when clearing WA_ShowModal
            data->window_modality = Qt::NonModal;
        } else if (data->window_modality == Qt::NonModal) {
            // determine the modality type if it hasn't been set prior
            // to setting WA_ShowModal. set the default to WindowModal
            // if we are the child of a group leader; otherwise use
            // ApplicationModal.
            QWidget *w = parentWidget();
            if (w)
                w = w->window();
            while (w && !w->testAttribute(Qt::WA_GroupLeader)) {
                w = w->parentWidget();
                if (w)
                    w = w->window();
            }
            data->window_modality = (w && w->testAttribute(Qt::WA_GroupLeader))
                                    ? Qt::WindowModal
                                    : Qt::ApplicationModal;
        }
        if (testAttribute(Qt::WA_WState_Created)) {
            // don't call setModal_sys() before create_sys()
            d->setModal_sys();
        }
        break;
    case Qt::WA_MouseTracking: {
        QEvent e(QEvent::MouseTrackingChange);
        QApplication::sendEvent(this, &e);
        break; }
#if !defined(QT_NO_DIRECT3D) && defined(Q_WS_WIN)
    case Qt::WA_MSWindowsUseDirect3D:
        if (!qApp->testAttribute(Qt::AA_MSWindowsUseDirect3DByDefault)) {
            if (on) {
                if (!d->extra)
                    d->createExtra();
                d->extra->had_auto_fill_bg = d->extra->autoFillBackground;
                d->extra->had_no_system_bg = testAttribute(Qt::WA_NoSystemBackground);
                d->extra->had_paint_on_screen = testAttribute(Qt::WA_PaintOnScreen);
                // enforce the opaque widget state D3D needs
                d->extra->autoFillBackground = true;
                setAttribute(Qt::WA_PaintOnScreen);
                setAttribute(Qt::WA_NoSystemBackground);
            } else if (d->extra) {
                d->extra->autoFillBackground = d->extra->had_auto_fill_bg;
                setAttribute(Qt::WA_PaintOnScreen, d->extra->had_paint_on_screen);
                setAttribute(Qt::WA_NoSystemBackground, d->extra->had_no_system_bg);
            }
        }
        break;
#endif
    case Qt::WA_NativeWindow:
        if (!qApp->testAttribute(Qt::AA_DontCreateNativeWidgetSiblings) && parentWidget())
            parentWidget()->d_func()->enforceNativeChildren();
        if (on && !internalWinId() && testAttribute(Qt::WA_WState_Created))
            d->createWinId();
        break;
    case Qt::WA_PaintOnScreen:
#if defined(Q_WS_WIN) || defined(Q_WS_X11)
        // Recreate the widget if it's already created as an alien widget and
        // WA_PaintOnScreen is enabled. Paint on screen widgets must have win id.
        // So must their children.
        if (on) {
            setAttribute(Qt::WA_NativeWindow);
            d->enforceNativeChildren();
        }
#endif
        // fall through
    case Qt::WA_OpaquePaintEvent:
        d->updateIsOpaque();
        break;
    case Qt::WA_NoSystemBackground:
        d->updateIsOpaque();
        // fall through...
    case Qt::WA_UpdatesDisabled:
        d->updateSystemBackground();
        break;
    case Qt::WA_TransparentForMouseEvents:
#ifdef Q_WS_MAC
        d->macUpdateIgnoreMouseEvents();
#endif
        break;
    case Qt::WA_InputMethodEnabled: {
#if defined(Q_WS_WIN) || (defined(Q_WS_QWS) && !defined(QT_NO_QWS_INPUTMETHODS))
        if (hasFocus())
            QInputContextPrivate::updateImeStatus(this, true);
#endif
        QInputContext *ic = d->inputContext();
        if (!on && ic && ic->focusWidget() == this) {
            ic->reset();
            ic->setFocusWidget(0);
        }
        break;
    }
    case Qt::WA_WindowPropagation:
        d->resolvePalette();
        d->resolveFont();
        d->resolveLocale();
        break;
#ifdef Q_WS_X11
    case Qt::WA_NoX11EventCompression:
        if (!d->extra)
            d->createExtra();
        d->extra->compress_events = on;
        break;
#endif
    case Qt::WA_DontShowOnScreen: {
        if (on && isVisible())
            d->hide_sys();
        break;
    }

#ifdef Q_WS_X11
    case Qt::WA_X11NetWmWindowTypeDesktop:
    case Qt::WA_X11NetWmWindowTypeDock:
    case Qt::WA_X11NetWmWindowTypeToolBar:
    case Qt::WA_X11NetWmWindowTypeMenu:
    case Qt::WA_X11NetWmWindowTypeUtility:
    case Qt::WA_X11NetWmWindowTypeSplash:
    case Qt::WA_X11NetWmWindowTypeDialog:
    case Qt::WA_X11NetWmWindowTypeDropDownMenu:
    case Qt::WA_X11NetWmWindowTypePopupMenu:
    case Qt::WA_X11NetWmWindowTypeToolTip:
    case Qt::WA_X11NetWmWindowTypeNotification:
    case Qt::WA_X11NetWmWindowTypeCombo:
    case Qt::WA_X11NetWmWindowTypeDND:
        if (testAttribute(Qt::WA_WState_Created))
            d->setNetWmWindowTypes();
        break;
#endif

    default:
        break;
    }
}


Generated by  Doxygen 1.6.0   Back to index