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

📄 qdialogbuttonbox.cpp

📁 奇趣公司比较新的qt/emd版本
💻 CPP
📖 第 1 页 / 共 3 页
字号:
    The button layout is specified by the \l{style()}{current style}.*//*!    \fn void QDialogButtonBox::clicked(QAbstractButton *button)    This signal is emitted when a button inside the button box is clicked. The    specific button that was pressed is specified by \a button.    \sa accepted(), rejected(), helpRequested()*//*!    \fn void QDialogButtonBox::accepted()    This signal is emitted when a button inside the button box is clicked, as long    as it was defined with the \l AcceptRole or \l YesRole.    \sa rejected(), clicked() helpRequested()*//*!    \fn void QDialogButtonBox::rejected()    This signal is emitted when a button inside the button box is clicked, as long    as it was defined with the \l RejectRole or \l NoRole.    \sa accepted() helpRequested() clicked()*//*!    \fn void QDialogButtonBox::helpRequested()    This signal is emitted when a button inside the button box is clicked, as long    as it was defined with the \l HelpRole.    \sa accepted() rejected() clicked()*//*!    \property QDialogButtonBox::orientation    \brief the orientation of the button box    By default, the orientation is horizontal (i.e. the buttons are laid out    side by side). The possible orientations are Qt::Horizontal and    Qt::Vertical.*/Qt::Orientation QDialogButtonBox::orientation() const{    return d_func()->orientation;}void QDialogButtonBox::setOrientation(Qt::Orientation orientation){    Q_D(QDialogButtonBox);    if (orientation == d->orientation)        return;    d->orientation = orientation;    d->resetLayout();}/*!    Clears the button box, deleting all buttons within it.    \sa removeButton(), addButton()*/void QDialogButtonBox::clear(){    Q_D(QDialogButtonBox);    // Remove the created standard buttons, they should be in the other lists, which will    // do the deletion    d->standardButtonHash.clear();    for (int i = 0; i < NRoles; ++i) {        QList<QAbstractButton *> &list = d->buttonLists[i];        while (list.count()) {            QAbstractButton *button = list.takeAt(0);            QObject::disconnect(button, SIGNAL(destroyed()), this, SLOT(_q_handleButtonDestroyed()));            delete button;        }    }}/*!    Returns a list of all the buttons that have been added to the button box.    \sa buttonRole(), addButton(), removeButton()*/QList<QAbstractButton *> QDialogButtonBox::buttons() const{    Q_D(const QDialogButtonBox);    QList<QAbstractButton *> finalList;    for (int i = 0; i < NRoles; ++i) {        const QList<QAbstractButton *> &list = d->buttonLists[i];        for (int j = 0; j < list.count(); ++j)            finalList.append(list.at(j));    }    return finalList;}/*!    Returns the button role for the specified \a button. This function returns    \l InvalidRole if \a button is 0 or has not been added to the button box.    \sa buttons(), addButton()*/QDialogButtonBox::ButtonRole QDialogButtonBox::buttonRole(QAbstractButton *button) const{    Q_D(const QDialogButtonBox);    for (int i = 0; i < NRoles; ++i) {        const QList<QAbstractButton *> &list = d->buttonLists[i];        for (int j = 0; j < list.count(); ++j) {            if (list.at(j) == button)                return ButtonRole(i);        }    }    return InvalidRole;}/*!    Removes \a button from the button box without deleting it and sets its parent to zero.    \sa clear(), buttons(), addButton()*/void QDialogButtonBox::removeButton(QAbstractButton *button){    Q_D(QDialogButtonBox);    if (!button)        return;    // Remove it from the standard button hash first and then from the roles    if (QPushButton *pushButton = qobject_cast<QPushButton *>(button))        d->standardButtonHash.remove(pushButton);    for (int i = 0; i < NRoles; ++i) {        QList<QAbstractButton *> &list = d->buttonLists[i];        for (int j = 0; j < list.count(); ++j) {            if (list.at(j) == button) {                list.takeAt(j);                if (!d->internalRemove) {                    disconnect(button, SIGNAL(clicked()), this, SLOT(_q_handleButtonClicked()));                    disconnect(button, SIGNAL(destroyed()), this, SLOT(_q_handleButtonDestroyed()));                }                break;            }        }    }    if (!d->internalRemove)        button->setParent(0);}/*!    Adds the given \a button to the button box with the specified \a role.    If the role is invalid, the button is not added.    If the button has already been added, it is removed and added again with the    new role.    \sa removeButton(), clear()*/void QDialogButtonBox::addButton(QAbstractButton *button, ButtonRole role){    Q_D(QDialogButtonBox);    if (role <= InvalidRole || role >= NRoles) {        qWarning("QDialogButtonBox::addButton: Invalid ButtonRole, button not added");        return;    }    removeButton(button);    button->setParent(this);    d->addButton(button, role);}/*!    Creates a push button with the given \a text, adds it to the button box for the    specified \a role, and returns the corresponding push button. If \a role is    invalid, no button is created, and zero is returned.    \sa removeButton(), clear()*/QPushButton *QDialogButtonBox::addButton(const QString &text, ButtonRole role){    Q_D(QDialogButtonBox);    if (role <= InvalidRole || role >= NRoles) {        qWarning("QDialogButtonBox::addButton: Invalid ButtonRole, button not added");        return 0;    }    QPushButton *button = new QPushButton(text, this);    d->addButton(button, role);    return button;}/*!    Adds a standard \a button to the button box if it is valid to do so, and returns    a push button. If \a button is invalid, it is not added to the button box, and    zero is returned.    \sa removeButton(), clear()*/QPushButton *QDialogButtonBox::addButton(StandardButton button){    Q_D(QDialogButtonBox);    return d->createButton(button);}/*!    \property QDialogButtonBox::standardButtons    \brief collection of standard buttons in the button box    This property controls which standard buttons are used by the button box.    \sa addButton()*/void QDialogButtonBox::setStandardButtons(StandardButtons buttons){    Q_D(QDialogButtonBox);    // Clear out all the old standard buttons, then recreate them.    qDeleteAll(d->standardButtonHash.keys());    d->standardButtonHash.clear();    d->createStandardButtons(buttons);}QDialogButtonBox::StandardButtons QDialogButtonBox::standardButtons() const{    Q_D(const QDialogButtonBox);    StandardButtons standardButtons = NoButton;    QHash<QPushButton *, StandardButton>::const_iterator it = d->standardButtonHash.constBegin();    while (it != d->standardButtonHash.constEnd()) {        standardButtons |= it.value();        ++it;    }    return standardButtons;}/*!    Returns the QPushButton corresponding to the standard button \a which,    or 0 if the standard button doesn't exist in this button box.    \sa standardButton(), standardButtons(), buttons()*/QPushButton *QDialogButtonBox::button(StandardButton which) const{    Q_D(const QDialogButtonBox);    return d->standardButtonHash.key(which);}/*!    Returns the standard button enum value corresponding to the given \a button,    or NoButton if the given \a button isn't a standard button.    \sa button(), buttons(), standardButtons()*/QDialogButtonBox::StandardButton QDialogButtonBox::standardButton(QAbstractButton *button) const{    Q_D(const QDialogButtonBox);    return d->standardButtonHash.value(static_cast<QPushButton *>(button));}void QDialogButtonBoxPrivate::_q_handleButtonClicked(){    Q_Q(QDialogButtonBox);    if (QAbstractButton *button = qobject_cast<QAbstractButton *>(q->sender())) {        emit q->clicked(button);        switch (q->buttonRole(button)) {        case AcceptRole:        case YesRole:            emit q->accepted();            break;        case RejectRole:        case NoRole:            emit q->rejected();            break;        case HelpRole:            emit q->helpRequested();            break;        default:            break;        }    }}void QDialogButtonBoxPrivate::_q_handleButtonDestroyed(){    Q_Q(QDialogButtonBox);    if (QObject *object = q->sender()) {        QBoolBlocker skippy(internalRemove);        q->removeButton(static_cast<QAbstractButton *>(object));    }}/*!    \property QDialogButtonBox::centerButtons    \brief whether the buttons in the button box are centered    By default, this property is false. This behavior is appopriate    for most types of dialogs. A notable exception is message boxes    on most platforms (e.g. Windows), where the button box is    centered horizontally.    \sa QMessageBox*/void QDialogButtonBox::setCenterButtons(bool center){    Q_D(QDialogButtonBox);    if (d->center != center) {        d->center = center;        d->resetLayout();    }}bool QDialogButtonBox::centerButtons() const{    Q_D(const QDialogButtonBox);    return d->center;}/*!    \reimp*/void QDialogButtonBox::changeEvent(QEvent *event){    Q_D(QDialogButtonBox);    switch (event->type()) {    case QEvent::StyleChange:#ifdef Q_WS_MAC    case QEvent::MacSizeChange:#endif        d->resetLayout();        QWidget::changeEvent(event);        break;    default:        QWidget::changeEvent(event);        break;    }}/*!    \reimp*/bool QDialogButtonBox::event(QEvent *event){    Q_D(QDialogButtonBox);    if (event->type() == QEvent::Show) {        QList<QAbstractButton *> acceptRoleList = d->buttonLists[AcceptRole];        QPushButton *firstAcceptButton = acceptRoleList.isEmpty() ? 0 : qobject_cast<QPushButton *>(acceptRoleList.at(0));        bool hasDefault = false;        for (int i = d->buttonLayout->count() - 1; i >= 0; --i) {            QLayoutItem *item = d->buttonLayout->itemAt(i);            if (QPushButton *pb = qobject_cast<QPushButton *>(item->widget())) {                if (pb->isDefault() && pb != firstAcceptButton) {                    hasDefault = true;                    break;                }            }        }        if (!hasDefault && firstAcceptButton)            firstAcceptButton->setDefault(true);    }else if (event->type() == QEvent::LanguageChange) {        d->retranslateStrings();    }    return QWidget::event(event);}#include "moc_qdialogbuttonbox.cpp"

⌨️ 快捷键说明

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