⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 qlayout.cpp

📁 奇趣公司比较新的qt/emd版本
💻 CPP
📖 第 1 页 / 共 3 页
字号:
    \sa sizeHint()*/Qt::Orientations QLayout::expandingDirections() const{    return Qt::Horizontal | Qt::Vertical;}void QLayout::activateRecursiveHelper(QLayoutItem *item){    item->invalidate();    QLayout *layout = item->layout();    if (layout) {        QLayoutItem *child;        int i=0;        while ((child = layout->itemAt(i++)))            activateRecursiveHelper(child);        layout->d_func()->activated = true;    }}/*!  Updates the layout for parentWidget().  You should generally not need to call this because it is  automatically called at the most appropriate times.  \sa activate(), invalidate()*/void QLayout::update(){    QLayout *layout = this;    while (layout && layout->d_func()->activated) {        layout->d_func()->activated = false;        if (layout->d_func()->topLevel) {            Q_ASSERT(layout->parent()->isWidgetType());            QWidget *mw = static_cast<QWidget*>(layout->parent());            if (mw->isVisible())                QApplication::postEvent(mw, new QEvent(QEvent::LayoutRequest));            break;        }        layout = static_cast<QLayout*>(layout->parent());    }}/*!    Redoes the layout for parentWidget() if necessary.    You should generally not need to call this because it is    automatically called at the most appropriate times. It returns    true if the layout was redone.    \sa update(), QWidget::updateGeometry()*/bool QLayout::activate(){    Q_D(QLayout);    if (!d->enabled || !parent())        return false;    if (!d->topLevel)        return static_cast<QLayout*>(parent())->activate();    if (d->activated)        return false;    QWidget *mw = static_cast<QWidget*>(parent());    if (mw == 0) {        qWarning("QLayout::activate: %s \"%s\" does not have a main widget",                 QObject::metaObject()->className(), QObject::objectName().toLocal8Bit().data());        return false;    }    activateRecursiveHelper(this);    QWidgetPrivate *md = mw->d_func();    uint explMin = md->extra ? md->extra->explicitMinSize : 0;    switch (d->constraint) {    case SetFixedSize:        // will trigger resize        mw->setFixedSize(totalSizeHint());        break;    case SetMinimumSize:        mw->setMinimumSize(totalMinimumSize());        break;    case SetMaximumSize:        mw->setMaximumSize(totalMaximumSize());        break;    case SetMinAndMaxSize:        mw->setMinimumSize(totalMinimumSize());        mw->setMaximumSize(totalMaximumSize());        break;    case SetDefaultConstraint: {        bool widthSet = explMin & Qt::Horizontal;        bool heightSet = explMin & Qt::Vertical;        if (mw->isWindow()) {            QSize ms = totalMinimumSize();            if (widthSet)                ms.setWidth(mw->minimumSize().width());            if (heightSet)                ms.setHeight(mw->minimumSize().height());            if ((!heightSet || !widthSet) && hasHeightForWidth()) {                int h = minimumHeightForWidth(ms.width());                if (h > ms.height()) {                    if (!heightSet)                        ms.setHeight(0);                    if (!widthSet)                        ms.setWidth(0);                }            }            mw->setMinimumSize(ms);        } else if (!widthSet || !heightSet) {            QSize ms = mw->minimumSize();            if (!widthSet)                ms.setWidth(0);            if (!heightSet)                ms.setHeight(0);            mw->setMinimumSize(ms);        }        break;    }    case SetNoConstraint:        break;    }    d->doResize(mw->size());    if (md->extra)        md->extra->explicitMinSize = explMin;    // ideally only if sizeHint() or sizePolicy() has changed    mw->updateGeometry();    return true;}/*!    \fn QLayoutItem *QLayout::itemAt(int index) const    Must be implemented in subclasses to return the layout item at \a    index. If there is no such item, the function must return 0.    Items are numbered consecutively from 0. If an item is deleted, other items will be renumbered.    This function can be used to iterate over a layout. The following    code will draw a rectangle for each layout item in the layout structure of the widget.    \code        static void paintLayout(QPainter *painter, QLayoutItem *item)        {            QLayout *layout = item->layout();            if (layout) {                for (int i = 0; i < layout->count(); ++i)                    paintLayout(painter, layout->itemAt(i));            }            painter->drawRect(layout->geometry());        }        void MyWidget::paintEvent(QPaintEvent *)        {            QPainter painter(this);            if (layout())                paintLayout(&painter, layout());        }    \endcode    \sa count(), takeAt()*//*!    \fn QLayoutItem *QLayout::takeAt(int index)    Must be implemented in subclasses to remove the layout item at \a    index from the layout, and return the item. If there is no such    item, the function must do nothing and return 0.  Items are numbered    consecutively from 0. If an item is deleted, other items will be    renumbered.    The following code fragment shows a safe way to remove all items    from a layout:    \code        QLayoutItem *child;        while ((child = layout->takeAt(0)) != 0) {            ...            delete child;        }    \endcode    \sa itemAt(), count()*//*!    \fn int *QLayout::count() const    Must be implemented in subclasses to return the number of items    in the layout.    \sa itemAt()*//*!    Searches for widget \a widget in this layout (not including child    layouts).    Returns the index of \a widget, or -1 if \a widget is not found.    The default implementation iterates over all items using itemAt()*/int QLayout::indexOf(QWidget *widget) const{    int i = 0;    QLayoutItem *item = itemAt(i);    while (item) {        if (item->widget() == widget)            return i;        ++i;        item = itemAt(i);    }    return -1;}/*!    \enum QLayout::SizeConstraint    The possible values are:    \value SetDefaultConstraint The main widget's minimum size is set                    to minimumSize(), unless the widget already has                    a minimum size.    \value SetFixedSize The main widget's size is set to sizeHint(); it                    cannot be resized at all.    \value SetMinimumSize  The main widget's minimum size is set to                    minimumSize(); it cannot be smaller.    \value SetMaximumSize  The main widget's maximum size is set to                    maximumSize(); it cannot be larger.    \value SetMinAndMaxSize  The main widget's minimum size is set to                    minimumSize() and its maximum size is set to                    maximumSize().    \value SetNoConstraint  The widget is not constrained.    \omitvalue Auto    \omitvalue FreeResize    \omitvalue Minimum    \omitvalue Fixed    \sa setSizeConstraint()*//*!    \property QLayout::sizeConstraint    \brief the resize mode of the layout    The default mode is \l SetDefaultConstraint.*/void QLayout::setSizeConstraint(SizeConstraint constraint){    Q_D(QLayout);    if (constraint == d->constraint)        return;    d->constraint = constraint;    invalidate();}QLayout::SizeConstraint QLayout::sizeConstraint() const{    Q_D(const QLayout);    return d->constraint;}/*!    Returns the rectangle that should be covered when the geometry of    this layout is set to \a r, provided that this layout supports    setAlignment().    The result is derived from sizeHint() and expanding(). It is never    larger than \a r.*/QRect QLayout::alignmentRect(const QRect &r) const{    QSize s = sizeHint();    Qt::Alignment a = alignment();    /*      This is a hack to obtain the real maximum size, not      QSize(QLAYOUTSIZE_MAX, QLAYOUTSIZE_MAX), the value consistently      returned by QLayoutItems that have an alignment.    */    QLayout *that = const_cast<QLayout *>(this);    that->setAlignment(0);    QSize ms = that->maximumSize();    that->setAlignment(a);    if ((expandingDirections() & Qt::Horizontal) ||         !(a & Qt::AlignHorizontal_Mask)) {        s.setWidth(qMin(r.width(), ms.width()));    }    if ((expandingDirections() & Qt::Vertical) ||         !(a & Qt::AlignVertical_Mask)) {        s.setHeight(qMin(r.height(), ms.height()));    } else if (hasHeightForWidth()) {        int hfw = heightForWidth(s.width());        if (hfw < s.height())            s.setHeight(qMin(hfw, ms.height()));    }    int x = r.x();    int y = r.y();    if (a & Qt::AlignBottom)        y += (r.height() - s.height());    else if (!(a & Qt::AlignTop))        y += (r.height() - s.height()) / 2;    QWidget *parent = parentWidget();    a = QStyle::visualAlignment(parent ? parent->layoutDirection() : QApplication::layoutDirection(), a);    if (a & Qt::AlignRight)        x += (r.width() - s.width());    else if (!(a & Qt::AlignLeft))        x += (r.width() - s.width()) / 2;    return QRect(x, y, s.width(), s.height());}/*!    Removes the widget \a widget from the layout. After this call, it    is the caller's responsibility to give the widget a reasonable    geometry or to put the widget back into a layout.        \bold{Note:} The ownership of \a widget remains the same as    when it was added.    \sa removeItem(), QWidget::setGeometry(), addWidget()*/void QLayout::removeWidget(QWidget *widget){    int i = 0;    QLayoutItem *child;    while ((child = itemAt(i))) {        if (child->widget() == widget) {            delete takeAt(i);            invalidate();        } else {            ++i;        }    }}/*!    Removes the layout item \a item from the layout. It is the    caller's responsibility to delete the item.    Notice that \a item can be a layout (since QLayout inherits    QLayoutItem).    \sa removeWidget(), addItem()*/void QLayout::removeItem(QLayoutItem *item){    int i = 0;    QLayoutItem *child;    while ((child = itemAt(i))) {        if (child == item) {            takeAt(i);            invalidate();        } else {            ++i;        }    }}/*!    Enables this layout if \a enable is true, otherwise disables it.    An enabled layout adjusts dynamically to changes; a disabled    layout acts as if it did not exist.    By default all layouts are enabled.    \sa isEnabled()*/void QLayout::setEnabled(bool enable){    Q_D(QLayout);    d->enabled = enable;}/*!    Returns true if the layout is enabled; otherwise returns false.    \sa setEnabled()*/bool QLayout::isEnabled() const{    Q_D(const QLayout);    return d->enabled;}/*!    Returns a size that satisfies all size constraints on \a widget,    including heightForWidth() and that is as close as possible to \a    size.*/QSize QLayout::closestAcceptableSize(const QWidget *widget, const QSize &size){    QSize result = size.boundedTo(qSmartMaxSize(widget));    result = result.expandedTo(qSmartMinSize(widget));    QLayout *l = widget->layout();    if (l && l->hasHeightForWidth() && result.height() < l->minimumHeightForWidth(result.width()) ) {        QSize current = widget->size();        int currentHfw =  l->minimumHeightForWidth(current.width());        int newHfw = l->minimumHeightForWidth(result.width());        if (current.height() < currentHfw || currentHfw == newHfw) {            //handle the constant hfw case and the vertical-only case, as well as the            // current-size-is-not-correct case            result.setHeight(newHfw);        } else {            // binary search; assume hfw is decreasing ###            int maxw = qMax(widget->width(),result.width());            int maxh = qMax(widget->height(), result.height());            int minw = qMin(widget->width(),result.width());            int minh = qMin(widget->height(), result.height());            int minhfw = l->minimumHeightForWidth(minw);            int maxhfw = l->minimumHeightForWidth(maxw);            while (minw < maxw) {                if (minhfw > maxh) { //assume decreasing                    minw = maxw - (maxw-minw)/2;                    minhfw = l->minimumHeightForWidth(minw);                } else if (maxhfw < minh ) { //assume decreasing                    maxw = minw + (maxw-minw)/2;                    maxhfw = l->minimumHeightForWidth(maxw);                } else  {                    break;                }            }            result = result.expandedTo(QSize(minw, minhfw));        }    }    return result;}/*!    \fn void QLayout::setResizeMode(SizeConstraint constraint)    Use setSizeConstraint(\a constraint) instead.*//*!    \fn QLayout::SizeConstraint QLayout::resizeMode() const    Use sizeConstraint() instead.*/void QSizePolicy::setControlType(ControlType type){    /*        The control type is a flag type, with values 0x1, 0x2, 0x4, 0x8, 0x10,        etc. In memory, we pack it onto the available bits (CTSize) in        setControlType(), and unpack it here.        Example:            0x00000001 maps to 0x00000000            0x00000002 maps to 0x00000200            0x00000004 maps to 0x00000400            0x00000008 maps to 0x00000600            etc.    */    int i = 0;    while (true) {        if (type & (0x1 << i)) {            data = (data & ~CTMask) | (i << CTShift);            return;        }        ++i;    }}QSizePolicy::ControlType QSizePolicy::controlType() const{    return QSizePolicy::ControlType(0x1 << ((data & CTMask) >> CTShift));}#ifndef QT_NO_DATASTREAM/*!    \relates QSizePolicy    \since 4.2    Writes the size \a policy to the data stream \a stream.    \sa \link datastreamformat.html Format of the QDataStream operators \endlink*/QDataStream &operator<<(QDataStream &stream, const QSizePolicy &policy){    return stream << policy.data;}/*!    \relates QSizePolicy    \since 4.2    Reads the size \a policy from the data stream \a stream.    \sa \link datastreamformat.html Format of the QDataStream operators \endlink*/QDataStream &operator>>(QDataStream &stream, QSizePolicy &policy){    return stream >> policy.data;}#endif

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -