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

📄 qgroupbox.cpp

📁 奇趣公司比较新的qt/emd版本
💻 CPP
📖 第 1 页 / 共 2 页
字号:
            d->pressedControl = QStyle::SC_None;            if (toggle)                d->click();            return true;        }        break;    }    default:        break;    }    return QWidget::event(e);}/*!\reimp */void QGroupBox::childEvent(QChildEvent *c){    Q_D(QGroupBox);    if (c->type() != QEvent::ChildAdded || !c->child()->isWidgetType())        return;    QWidget *w = (QWidget*)c->child();    if (d->checkable) {        if (d->checked) {            if (!w->testAttribute(Qt::WA_ForceDisabled))                w->setEnabled(true);        } else {            if (w->isEnabled()) {                w->setEnabled(false);                w->setAttribute(Qt::WA_ForceDisabled, false);            }        }    }}/*!    \internal    This private slot finds a widget in this group box that can accept    focus, and gives the focus to that widget.*/void QGroupBoxPrivate::_q_fixFocus(Qt::FocusReason reason){    Q_Q(QGroupBox);    QWidget *fw = q->focusWidget();    if (!fw) {        QWidget * best = 0;        QWidget * candidate = 0;        QWidget * w = q;        while ((w = w->nextInFocusChain()) != q) {            if (q->isAncestorOf(w) && (w->focusPolicy() & Qt::TabFocus) == Qt::TabFocus && w->isVisibleTo(q)) {                if (!best && qobject_cast<QRadioButton*>(w) && ((QRadioButton*)w)->isChecked())                    // we prefer a checked radio button or a widget that                    // already has focus, if there is one                    best = w;                else                    if (!candidate)                        // but we'll accept anything that takes focus                        candidate = w;            }        }        if (best)            fw = best;        else            if (candidate)                fw = candidate;    }    if (fw)        fw->setFocus(reason);}/*    Sets the right frame rect depending on the title.*/void QGroupBoxPrivate::calculateFrame(){    Q_Q(QGroupBox);    QStyleOptionGroupBox box;    q->initStyleOption(&box);    QRect contentsRect = q->style()->subControlRect(QStyle::CC_GroupBox, &box, QStyle::SC_GroupBoxContents, q);    q->setContentsMargins(contentsRect.left() - box.rect.left(), contentsRect.top() - box.rect.top(),                          box.rect.right() - contentsRect.right(), box.rect.bottom() - contentsRect.bottom());    setLayoutItemMargins(QStyle::SE_GroupBoxLayoutItem, &box);}/*! \reimp */void QGroupBox::focusInEvent(QFocusEvent *fe){ // note no call to super    Q_D(QGroupBox);    if (focusPolicy() == Qt::NoFocus) {        d->_q_fixFocus(fe->reason());    } else {        QStyleOptionGroupBox box;        initStyleOption(&box);        QRect rect = style()->subControlRect(QStyle::CC_GroupBox, &box, QStyle::SC_GroupBoxCheckBox, this)            | style()->subControlRect(QStyle::CC_GroupBox, &box, QStyle::SC_GroupBoxLabel, this);        update(rect);    }}/*!  \reimp*/QSize QGroupBox::minimumSizeHint() const{    Q_D(const QGroupBox);    QStyleOptionGroupBox option;    initStyleOption(&option);    QFontMetrics metrics(fontMetrics());    int baseWidth = metrics.width(d->title) + metrics.width(QLatin1Char(' '));    int baseHeight = metrics.height();    if (d->checkable) {        baseWidth += style()->pixelMetric(QStyle::PM_IndicatorWidth);        baseWidth += style()->pixelMetric(QStyle::PM_CheckBoxLabelSpacing);        baseHeight = qMax(baseHeight, style()->pixelMetric(QStyle::PM_IndicatorHeight));    }    QSize size = style()->sizeFromContents(QStyle::CT_GroupBox, &option, QSize(baseWidth, baseHeight), this);    return size.expandedTo(QWidget::minimumSizeHint());}/*!    \property QGroupBox::flat    \brief whether the group box is painted flat or has a frame    A group box usually consists of a surrounding frame with a title    at the top. If this property is enabled, only the top part of the frame is    drawn in most styles; otherwise the whole frame is drawn.    By default, this property is disabled; i.e. group boxes are not flat unless    explicitly specified.    \bold{Note:} In some styles, flat and non-flat group boxes have similar    representations and may not be as distinguishable as they are in other    styles.    \sa title*/bool QGroupBox::isFlat() const{    Q_D(const QGroupBox);    return d->flat;}void QGroupBox::setFlat(bool b){    Q_D(QGroupBox);    if (d->flat == b)        return;    d->flat = b;    updateGeometry();    update();}/*!    \property QGroupBox::checkable    \brief whether the group box has a checkbox in its title    If this property is true, the group box displays its title using    a checkbox in place of an ordinary label. If the checkbox is checked,    the group box's children are enabled; otherwise they are disabled and    inaccessible.    By default, group boxes are not checkable.    If this property is enabled for a group box, it will also be initially    checked to ensure that its contents are enabled.    \sa checked*/void QGroupBox::setCheckable(bool checkable){    Q_D(QGroupBox);    bool wasCheckable = d->checkable;    d->checkable = checkable;    if (checkable) {        setChecked(true);        if (!wasCheckable) {            setFocusPolicy(Qt::StrongFocus);            d->_q_setChildrenEnabled(true);            updateGeometry();        }    } else {        if (wasCheckable) {            setFocusPolicy(Qt::NoFocus);            d->_q_setChildrenEnabled(true);            updateGeometry();        }        d->_q_setChildrenEnabled(true);    }    if (wasCheckable != checkable) {        d->calculateFrame();        update();    }}bool QGroupBox::isCheckable() const{    Q_D(const QGroupBox);    return d->checkable;}bool QGroupBox::isChecked() const{    Q_D(const QGroupBox);    return d->checkable && d->checked;}/*!    \fn void QGroupBox::toggled(bool on)    If the group box is checkable, this signal is emitted when the check box    is toggled. \a on is true if the check box is checked; otherwise it is false.    \sa checkable*//*!    \fn void QGroupBox::clicked(bool checked)    \since 4.2    This signal is emitted when the check box is activated (i.e. pressed down    then released while the mouse cursor is inside the button), or when the    shortcut key is typed, Notably, this signal is \e not emitted if you call    setChecked().    If the check box is checked \a checked is true; it is false if the check    box is unchecked.    \sa checkable, toggled(), checked*//*!    \property QGroupBox::checked    \brief whether the group box is checked    If the group box is checkable, it is displayed with a check box.    If the check box is checked, the group box's children are enabled;    otherwise the children are disabled and are inaccessible to the user.    By default, checkable group boxes are also checked.    \sa checkable*/void QGroupBox::setChecked(bool b){    Q_D(QGroupBox);    if (d->checkable) {        if (d->checked != b)            update();        bool wasToggled = (b != d->checked);        d->checked = b;        if (wasToggled) {            d->_q_setChildrenEnabled(b);            emit toggled(b);        }    }}/*  sets all children of the group box except the qt_groupbox_checkbox  to either disabled/enabled*/void QGroupBoxPrivate::_q_setChildrenEnabled(bool b){    Q_Q(QGroupBox);    QObjectList childList = q->children();    for (int i = 0; i < childList.size(); ++i) {        QObject *o = childList.at(i);        if (o->isWidgetType()) {            QWidget *w = static_cast<QWidget *>(o);            if (b) {                if (!w->testAttribute(Qt::WA_ForceDisabled))                    w->setEnabled(true);            } else {                if (w->isEnabled()) {                    w->setEnabled(false);                    w->setAttribute(Qt::WA_ForceDisabled, false);                }            }        }    }}/*! \reimp */void QGroupBox::changeEvent(QEvent *ev){    Q_D(QGroupBox);    if (ev->type() == QEvent::EnabledChange) {        if (d->checkable && isEnabled()) {            // we are being enabled - disable children            if (!d->checked)                d->_q_setChildrenEnabled(false);        }    } else if (ev->type() == QEvent::FontChange#ifdef Q_WS_MAC               || ev->type() == QEvent::MacSizeChange#endif               || ev->type() == QEvent::StyleChange) {        d->calculateFrame();    }    QWidget::changeEvent(ev);}/*! \reimp */void QGroupBox::mousePressEvent(QMouseEvent *event){    Q_D(QGroupBox);    QStyleOptionGroupBox box;    initStyleOption(&box);    d->pressedControl = style()->hitTestComplexControl(QStyle::CC_GroupBox, &box,                                                       event->pos(), this);    if (d->checkable && (d->pressedControl & (QStyle::SC_GroupBoxCheckBox | QStyle::SC_GroupBoxLabel)))        update(style()->subControlRect(QStyle::CC_GroupBox, &box, QStyle::SC_GroupBoxCheckBox, this));}/*! \reimp */void QGroupBox::mouseMoveEvent(QMouseEvent *event){    Q_D(QGroupBox);    QStyleOptionGroupBox box;    initStyleOption(&box);    QStyle::SubControl pressed = style()->hitTestComplexControl(QStyle::CC_GroupBox, &box,                                                                event->pos(), this);    if (d->pressedControl == QStyle::SC_GroupBoxCheckBox && d->pressedControl != pressed)        update(style()->subControlRect(QStyle::CC_GroupBox, &box, QStyle::SC_GroupBoxCheckBox, this));}/*! \reimp */void QGroupBox::mouseReleaseEvent(QMouseEvent *){    Q_D(QGroupBox);    QStyleOptionGroupBox box;    initStyleOption(&box);    bool toggle = d->checkable && (d->pressedControl == QStyle::SC_GroupBoxLabel                   || d->pressedControl == QStyle::SC_GroupBoxCheckBox);    d->pressedControl = QStyle::SC_None;    if (toggle)        d->click();}#ifdef QT3_SUPPORT/*!    Use one of the constructors that doesn't take the \a name    argument and then use setObjectName() instead.*/QGroupBox::QGroupBox(QWidget *parent, const char *name)    : QWidget(*new QGroupBoxPrivate, parent, 0){    Q_D(QGroupBox);    setObjectName(QString::fromAscii(name));    d->init();}/*!    Use one of the constructors that doesn't take the \a name    argument and then use setObjectName() instead.*/QGroupBox::QGroupBox(const QString &title, QWidget *parent, const char *name)    : QWidget(*new QGroupBoxPrivate, parent, 0){    Q_D(QGroupBox);    setObjectName(QString::fromAscii(name));    d->init();    setTitle(title);}#endif // QT3_SUPPORT#include "moc_qgroupbox.cpp"#endif //QT_NO_GROUPBOX

⌨️ 快捷键说明

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