本文整理汇总了C++中QComboBox::setValidator方法的典型用法代码示例。如果您正苦于以下问题:C++ QComboBox::setValidator方法的具体用法?C++ QComboBox::setValidator怎么用?C++ QComboBox::setValidator使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类QComboBox
的用法示例。
在下文中一共展示了QComboBox::setValidator方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: val
QComboBox * TraceWire::createWidthComboBox(double m, QWidget * parent)
{
QComboBox * comboBox = new FocusOutComboBox(parent); // new QComboBox(parent);
comboBox->setEditable(true);
QIntValidator * intValidator = new QIntValidator(comboBox);
intValidator->setRange(MinTraceWidthMils, MaxTraceWidthMils);
comboBox->setValidator(intValidator);
int ix = 0;
if (!Wire::widths.contains(m)) {
Wire::widths.append(m);
qSort(Wire::widths.begin(), Wire::widths.end());
}
foreach(long widthValue, Wire::widths) {
QString widthName = Wire::widthTrans.value(widthValue, "");
QVariant val((int) widthValue);
comboBox->addItem(widthName.isEmpty() ? QString::number(widthValue) : widthName, val);
if (qAbs(m - widthValue) < .01) {
comboBox->setCurrentIndex(ix);
}
ix++;
}
示例2: fontInfo
SimpleFontDialog::SimpleFontDialog(const QFont& initial, QWidget* parent)
: QDialog(parent)
{
QFontComboBox* fontComboBox = new QFontComboBox(this);
fontComboBox->setCurrentFont(initial);
font = initial;
QVBoxLayout* familyLayout = new QVBoxLayout();
familyLayout->addWidget(new QLabel(tr("Family")));
familyLayout->addWidget(fontComboBox);
QList<int> sizes = QFontDatabase::standardSizes();
QComboBox* sizeComboBox = new QComboBox(this);
sizeComboBox->setEditable(true);
QIntValidator* sizeValidator = new QIntValidator(1, 512, this);
sizeComboBox->setValidator(sizeValidator);
int currentSizeIndex = 0;
QFontInfo fontInfo(initial);
bool currentFontInserted = false;
for (int i = 0; i < sizes.size(); i++)
{
int size = sizes[i];
// If the current font size is a non-standard size, then insert
// it in the appropriate place in the sorted list of fonts.
//
if ((fontInfo.pointSize() < size) && !currentFontInserted)
{
currentSizeIndex = i;
sizeComboBox->addItem(QString("%1").arg(fontInfo.pointSize()), fontInfo.pointSize());
currentFontInserted = true;
}
// Else current font size is in the standard font sizes list. Set
// the index in the combo box to its position in the list.
//
else
{
if (fontInfo.pointSize() == size)
{
currentSizeIndex = i;
currentFontInserted = true;
}
}
sizeComboBox->addItem(QString("%1").arg(size), size);
}
if (!currentFontInserted)
{
sizeComboBox->addItem(QString("%1").arg(fontInfo.pointSize()), fontInfo.pointSize());
currentSizeIndex = sizeComboBox->count() - 1;
}
sizeComboBox->setCurrentIndex(currentSizeIndex);
QVBoxLayout* sizeLayout = new QVBoxLayout();
sizeLayout->addWidget(new QLabel(tr("Size")));
sizeLayout->addWidget(sizeComboBox);
fontPreview = new QLineEdit(tr("AaBbCcXxYyZz"), this);
fontPreview->setFont(initial);
QVBoxLayout* previewLayout = new QVBoxLayout();
previewLayout->addWidget(new QLabel(tr("Preview")));
previewLayout->addWidget(fontPreview);
QDialogButtonBox* buttonBox = new QDialogButtonBox(Qt::Horizontal, this);
buttonBox->addButton(QDialogButtonBox::Ok);
buttonBox->addButton(QDialogButtonBox::Cancel);
QGridLayout* layout = new QGridLayout();
layout->addItem(familyLayout, 0, 0);
layout->addItem(sizeLayout, 0, 1);
layout->addItem(previewLayout, 1, 0, 1, 2, Qt::AlignCenter);
layout->addWidget(buttonBox, 2, 0, 1, 2);
setLayout(layout);
connect(buttonBox, SIGNAL(accepted()), this, SLOT(accept()));
connect(buttonBox, SIGNAL(rejected()), this, SLOT(reject()));
connect(fontComboBox, SIGNAL(currentFontChanged(QFont)), this, SLOT(onFontFamilyChanged(const QFont&)));
connect(sizeComboBox, SIGNAL(currentIndexChanged(QString)), this, SLOT(onFontSizeChanged(const QString&)));
connect(sizeComboBox, SIGNAL(editTextChanged(QString)), this, SLOT(onFontSizeChanged(const QString&)));
}
示例3: if
//.........这里部分代码省略.........
pte = qobject_cast<QPlainTextEdit *>( editor );
cb = qobject_cast<QComboBox *>( editor );
}
else if ( editType == QgsVectorLayer::TextEdit )
{
pte = new QPlainTextEdit( parent );
}
else
{
le = new QLineEdit( parent );
}
if ( le )
{
if ( editType == QgsVectorLayer::UniqueValuesEditable )
{
QList<QVariant> values;
vl->dataProvider()->uniqueValues( idx, values );
QStringList svalues;
for ( QList<QVariant>::const_iterator it = values.begin(); it != values.end(); it++ )
svalues << it->toString();
QCompleter *c = new QCompleter( svalues );
c->setCompletionMode( QCompleter::PopupCompletion );
le->setCompleter( c );
}
if ( editType == QgsVectorLayer::UuidGenerator )
{
le->setReadOnly( true );
}
le->setValidator( new QgsFieldValidator( le, field ) );
myWidget = le;
}
if ( te )
{
te->setAcceptRichText( true );
myWidget = te;
}
if ( pte )
{
myWidget = pte;
}
if ( cb )
{
if ( cb->isEditable() )
cb->setValidator( new QgsFieldValidator( cb, field ) );
myWidget = cb;
}
if ( myWidget )
{
myWidget->setDisabled( editType == QgsVectorLayer::Immutable );
QgsStringRelay* relay = NULL;
QMap<int, QWidget*>::const_iterator it = proxyWidgets.find( idx );
if ( it != proxyWidgets.end() )
{
QObject* obj = qvariant_cast<QObject*>(( *it )->property( "QgisAttrEditProxy" ) );