本文整理汇总了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;
}
示例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);
}
}