当前位置: 首页>>代码示例>>C++>>正文


C++ QComboBox::validator方法代码示例

本文整理汇总了C++中QComboBox::validator方法的典型用法代码示例。如果您正苦于以下问题:C++ QComboBox::validator方法的具体用法?C++ QComboBox::validator怎么用?C++ QComboBox::validator使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在QComboBox的用法示例。


在下文中一共展示了QComboBox::validator方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: isValid

/**
 *  Returns true if all relevant children of the widget managed by this
 *  instance are valid AND if #isOtherValid() returns true; otherwise returns
 *  false. Disabled children and children without validation
 *  are skipped and don't affect the result.
 *
 *  The method emits the #isValidRequested() signal before calling
 *  #isOtherValid(), thus giving someone an opportunity to affect its result by
 *  calling #setOtherValid() from the signal handler. Note that #isOtherValid()
 *  returns true by default, until #setOtherValid( false ) is called.
 *
 *  @note If #isOtherValid() returns true this method does a hierarchy scan, so
 *  it's a good idea to store the returned value in a local variable if needed
 *  more than once within a context of a single check.
 */
bool QIWidgetValidator::isValid() const
{
    // wgt is null, we assume we're valid
    if (!mWidget)
        return true;

    QIWidgetValidator *that = const_cast <QIWidgetValidator *> (this);
    emit that->isValidRequested (that);
    if (!isOtherValid())
        return false;

    QValidator::State state = QValidator::Acceptable;

    foreach (Watched watched, mWatched)
    {
        if (watched.widget->inherits ("QLineEdit"))
        {
            QLineEdit *le = ((QLineEdit *) watched.widget);
            Assert (le->validator());
            if (!le->validator() || !le->isEnabled())
                continue;
            QString text = le->text();
            int pos;
            state = le->validator()->validate (text, pos);
        }
        else if (watched.widget->inherits ("QComboBox"))
        {
            QComboBox *cb = ((QComboBox *) watched.widget);
            Assert (cb->validator());
            if (!cb->validator() || !cb->isEnabled())
                continue;
            QString text = cb->lineEdit()->text();
            int pos;
            state = cb->lineEdit()->validator()->validate (text, pos);
        }

        if (state != QValidator::Acceptable)
        {
            that->mLastInvalid = watched;
            that->mLastInvalid.state = state;
            return false;
        }
    }

    /* reset last invalid */
    that->mLastInvalid = Watched();
    return true;
}
开发者ID:LastRitter,项目名称:vbox-haiku,代码行数:63,代码来源:QIWidgetValidator.cpp

示例2: checkValidity

void EditCallDialog::checkValidity(void)
{
    QValidator::State state = QValidator::Acceptable;
    
    int i;
    for (i=0; i<m_qObjects.size(); i++) {
        const FunctionCall::Argument *arg = m_pChangedCall->getArgument(i);
        switch (arg->iType) {
            case DBG_TYPE_ENUM:
                {
                    QComboBox *cb = (QComboBox*)m_qObjects[i];
                    const QValidator *vldr = cb->validator();
                    QString s = cb->currentText();
                    int pos = 0;
                    if (vldr->validate(s, pos) != QValidator::Acceptable) {
                        state = QValidator::Invalid;
                    }
                    break;
                }
            default:
                break;
        }
    }

    /* Find OK button */
    QAbstractButton *okButton = NULL;
    QList<QAbstractButton*> buttonList;
    buttonList = buttonBox->buttons();
    for(i=0; i<buttonList.size(); i++) {
        if (buttonBox->buttonRole(buttonList[i]) == 
                QDialogButtonBox::AcceptRole) {
            okButton = buttonList[i];
        }
    }

    if (!okButton) {
        return;
    }

    if (state == QValidator::Acceptable) {
        okButton->setEnabled(true);
    } else {
        okButton->setEnabled(false);
    }
}
开发者ID:flyncode,项目名称:GLSL-Debugger,代码行数:45,代码来源:editCallDialog.cpp


注:本文中的QComboBox::validator方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。