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

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 7284 of file qwidget.cpp.

References QWidget::isWindow(), QWidget::parentWidget(), QObject::qobject_cast(), QCoreApplication::sendEvent(), QWidget::setAttribute(), QWidget::testAttribute(), and QWidget::window().

Referenced by QMenu::actionEvent(), QLayout::addChildWidget(), QGroupBox::childEvent(), QAbstractFormBuilder::create(), QWidget::create(), QWidget::destroy(), QAbstractButton::event(), QWidget::event(), QLabel::event(), QDialog::exec(), QWidget::grabShortcut(), Q3ListView::handleSizeChange(), QCalendarWidget::mousePressEvent(), QMenu::mousePressEvent(), QApplication::notify(), QPlastiqueStyle::polish(), QCleanlooksStyle::polish(), QWindowsXPStyle::polish(), Q3Frame::Q3Frame(), QFocusFrame::QFocusFrame(), QGLWidget::QGLWidget(), QGraphicsView::QGraphicsView(), QMenu::QMenu(), QPageSetupDialog::QPageSetupDialog(), QRubberBand::QRubberBand(), QWidget::setAttribute(), QWidget::setContentsMargins(), QFrame::setFrameStyle(), QComboBox::setLineEdit(), QWidget::setMaximumSize(), QWidget::setMinimumSize(), QWidget::setParent(), QWidget::setStyle(), Q3MainWindow::setVisible(), QDialog::setVisible(), QWidget::setWindowState(), QDialog::showEvent(), Q3DockWindow::undock(), QPlastiqueStyle::unpolish(), QWindowsXPStyle::unpolish(), and QCleanlooksStyle::unpolish().

{
    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_MacMetalStyle:
#ifdef Q_WS_MAC
        extern void qt_mac_update_metal_style(QWidget*); //qwidget_mac.cpp
        qt_mac_update_metal_style(this);
#endif
        break;
    case Qt::WA_MacOpaqueSizeGrip:
#ifdef Q_WS_MAC
        extern void qt_mac_update_opaque_sizegrip(QWidget*); //qwidget_mac.cpp
        qt_mac_update_opaque_sizegrip(this);
#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; }
    case Qt::WA_PaintOnScreen:
    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
        extern void qt_mac_update_ignore_mouseevents(QWidget*); //qwidget_mac.cpp
        qt_mac_update_ignore_mouseevents(this);
#endif
        break;
#ifdef Q_WS_WIN
    case Qt::WA_InputMethodEnabled:
        QWinInputContext::enable(this, on);
        break;
#endif
    case Qt::WA_WindowPropagation:
        d->resolvePalette();
        d->resolveFont();
        break;
#ifdef Q_WS_X11
    case Qt::WA_NoX11EventCompression:
        if (!d->extra)
            d->createExtra();
        d->extra->compress_events = on;
        break;
#endif
    default:
        break;
    }
}


Generated by  Doxygen 1.6.0   Back to index