本文整理汇总了C++中QComboBox::setEditText方法的典型用法代码示例。如果您正苦于以下问题:C++ QComboBox::setEditText方法的具体用法?C++ QComboBox::setEditText怎么用?C++ QComboBox::setEditText使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类QComboBox
的用法示例。
在下文中一共展示了QComboBox::setEditText方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: setEditorData
void HopDelegate::setEditorData(QWidget *editor,
const QModelIndex &index) const
{
QComboBox *combo;
QSpinBox *spin;
QDoubleSpinBox *dspin;
int comboindex;
QVariant value = index.model()->data(index, Qt::EditRole);
// different kind of editor for each column
switch (index.column()) {
case HopModel::NAME:
combo = static_cast<QComboBox*>(editor);
if (!combo) return;
comboindex = combo->findText(value.toString());
if (comboindex > 0) {
combo->setCurrentIndex(comboindex);
} else {
combo->setEditText(value.toString());
}
break;
case HopModel::WEIGHT:
case HopModel::ALPHA:
dspin = static_cast<QDoubleSpinBox*>(editor);
if (!dspin) return;
dspin->setValue(value.toDouble());
break;
case HopModel::TIME:
spin = static_cast<QSpinBox*>(editor);
if (!spin) return;
spin->setValue(value.toUInt());
break;
case HopModel::TYPE:
combo = static_cast<QComboBox*>(editor);
if (!combo) return;
comboindex = combo->findText(value.toString());
if (comboindex > 0) {
combo->setCurrentIndex(comboindex);
} else {
combo->setEditText(value.toString());
}
break;
default:
QItemDelegate::setEditorData(editor, index);
break;
}
}
示例2: updateWidgetValue
void WidgetMOItem::updateWidgetValue(QWidget* curWidget, QVariant value)
{
QComboBox* combo = dynamic_cast<QComboBox*>(curWidget);
if(combo)
combo->setEditText(value.toString());
QSpinBox* spinBox = dynamic_cast<QSpinBox*>(curWidget);
if(spinBox)
spinBox->setValue(value.toInt());
QScienceSpinBox* doubleSpinBox = dynamic_cast<QScienceSpinBox*>(curWidget);
if(doubleSpinBox)
doubleSpinBox->setValue(value.toDouble());
QCheckBox* checkBox = dynamic_cast<QCheckBox*>(curWidget);
if(checkBox)
{
if(value.toBool())
checkBox->setCheckState(Qt::Checked);
else
checkBox->setCheckState(Qt::Unchecked);
}
QLineEdit* lineEdit = dynamic_cast<QLineEdit*>(curWidget);
if(lineEdit)
lineEdit->setText(value.toString());
}
示例3: setEditorData
//-----------------------------------------------------------------------------
// Function: FileTypesDelegate::setEditorData()
//-----------------------------------------------------------------------------
void FileTypesDelegate::setEditorData(QWidget* editor, const QModelIndex& index) const
{
switch (index.column())
{
case FILE_TYPES_COL_NAME:
{
QComboBox* combo = qobject_cast<QComboBox*>(editor);
Q_ASSERT_X(combo, "FileTypesDelegate::setEditorData", "Type conversion failed for QComboBox");
QString text = index.model()->data(index, Qt::DisplayRole).toString();
combo->setEditText(text);
break;
}
case FILE_TYPES_COL_EXTENSIONS:
{
QLineEdit* line = qobject_cast<QLineEdit*>(editor);
Q_ASSERT_X(line, "FileTypesDelegate::setEditorData", "Type conversion failed for QLineEdit");
QString text = index.model()->data(index, Qt::DisplayRole).toString();
line->setText(text);
break;
}
default:
{
QStyledItemDelegate::setEditorData(editor, index);
break;
}
}
}
示例4: updateFromAllowed
void MicroSelectWidget::updateFromAllowed()
{
QString oldFamily = m_pMicroFamily->currentText();
m_pMicroFamily->clear();
#define CHECK_ADD(family) \
if ( (m_allowedAsmSet & AsmInfo::family) \
&& !MicroLibrary::self()->microIDs( AsmInfo::family, \
m_allowedGpsimSupport, m_allowedFlowCodeSupport, m_allowedMicrobeSupport ).isEmpty() ) { \
m_pMicroFamily->insertItem( m_pMicroFamily->count(), AsmInfo::setToString(AsmInfo::family) ); \
}
CHECK_ADD(PIC12)
CHECK_ADD(PIC14)
CHECK_ADD(PIC16);
#undef CHECK_ADD
if ( m_pMicroFamily->contains(oldFamily) ) {
//m_pMicroFamily->setCurrentText(oldFamily); // 2018.12.07
{
QComboBox *c = m_pMicroFamily;
QString text = oldFamily;
int i = c->findText(text);
if (i != -1)
c->setCurrentIndex(i);
else if (c->isEditable())
c->setEditText(text);
else
c->setItemText(c->currentIndex(), text);
}
}
microFamilyChanged(oldFamily);
}
示例5: setOutputTabs
void ActionDialog::setOutputTabs(const QStringList &tabs,
const QString ¤tTabName)
{
QComboBox *w = ui->comboBoxOutputTab;
w->clear();
w->addItem("");
w->addItems(tabs);
w->setEditText(currentTabName);
}
示例6:
QComboBox *StManagerStudyListComp::createDirectoryComboBox ( const QString &text )
{
QComboBox *comboBox = new QComboBox;
comboBox->setEditable( true );
comboBox->setEditText( text );
return comboBox;
}
示例7: setEditorData
void ComboBoxDelegate::setEditorData(QWidget* editor, const QModelIndex& index) const
{
QComboBox *c = qobject_cast<QComboBox*>(editor);
QString data = index.model()->data(index, Qt::DisplayRole).toString();
int i = c->findText(data);
if (i != -1)
c->setCurrentIndex(i);
else
c->setEditText(data);
}
示例8: filterColumnName
//! Blocks disruptive characters from being entered in a column name field.
//! This function directly changes the text in the GUI combobox controls.
//! @param text The string to insert into the output CSV file after filtering
//! @see dataRowCreate()
void Window::filterColumnName(const QString &text)
{
QString filtered = text;
// The following characters cause problems with CSV and so are banned: \",
filtered.remove(QRegExp("[\\\\\\\",]"));
if(text.length() != filtered.length()) {
// To find out which combobox is being typed in, we have to request
// the sender. It arrives as a QObject, which we cast to a QComboBox
QComboBox * cBox = reinterpret_cast<QComboBox*>(QObject::sender());
cBox->setEditText(filtered);
}
}
示例9: lord
void Setting::lord(const QString& section, const QString& prefix, QComboBox& cmb, bool all)
{
cmb.clear();
QSettings& store = storage();
QStringList keys, vals;
store.beginGroup(section);
keys = store.childKeys();
qint32 n = keys.size();
if (n > 0)
{
QString tval;
QString tkey = prefix + SET_PFX_CMBTXT;
keys.sort();
while (n--)
{
QString k = keys[n];
if (k.startsWith(prefix))
{
QString v = store.value(k).toString().trimmed();
if (k == tkey)
tval = v;
else if (all && !v.isEmpty())
vals.append(v);
}
}
vals.removeDuplicates();
n = vals.count();
if (n > 0)
{
if (n > SET_MAX_CMBITM)
n = SET_MAX_CMBITM;
while (n--)
cmb.addItem(vals[n]);
}
if (!tval.isEmpty())
cmb.setEditText(tval);
}
store.endGroup();
}
示例10: setEditorData
void QUDefaultDelegate::setEditorData(
QWidget *editor,
const QModelIndex &index) const
{
QString value = index.model()->data(index, Qt::DisplayRole).toString();
QComboBox *comboBox = static_cast<QComboBox*>(editor);
if(QString::compare(value, N_A, Qt::CaseSensitive) == 0)
value = "";
comboBox->setEditText(value);
comboBox->lineEdit()->selectAll();
}
示例11: setMicro
void MicroSelectWidget::setMicro( const QString & id )
{
MicroInfo * info = MicroLibrary::self()->microInfoWithID(id);
if (!info)
return;
m_pMicro->clear();
m_pMicro->insertItems( m_pMicro->count(),
MicroLibrary::self()->microIDs( info->instructionSet()->set() ) );
//m_pMicro->setCurrentText(id); // 2018.12.07
{
QComboBox *c = m_pMicro;
QString text = id;
int i = c->findText(text);
if (i != -1)
c->setCurrentIndex(i);
else if (c->isEditable())
c->setEditText(text);
else
c->setItemText(c->currentIndex(), text);
}
//m_pMicroFamily->setCurrentText( AsmInfo::setToString( info->instructionSet()->set() ) ); // 2018.12.07
{
QComboBox *c = m_pMicroFamily;
QString text = AsmInfo::setToString( info->instructionSet()->set() );
int i = c->findText(text);
if (i != -1)
c->setCurrentIndex(i);
else if (c->isEditable())
c->setEditText(text);
else
c->setItemText(c->currentIndex(), text);
}
}
示例12: comboBox
void tst_QDataWidgetMapper::comboBox()
{
QDataWidgetMapper mapper;
QAbstractItemModel *model = testModel(&mapper);
mapper.setModel(model);
mapper.setSubmitPolicy(QDataWidgetMapper::ManualSubmit);
QComboBox readOnlyBox;
readOnlyBox.setEditable(false);
readOnlyBox.addItem("read only item 0");
readOnlyBox.addItem("read only item 1");
readOnlyBox.addItem("read only item 2");
QComboBox readWriteBox;
readWriteBox.setEditable(true);
readWriteBox.addItem("read write item 0");
readWriteBox.addItem("read write item 1");
readWriteBox.addItem("read write item 2");
// populat the combo boxes with data
mapper.addMapping(&readOnlyBox, 0, "currentIndex");
mapper.addMapping(&readWriteBox, 1, "currentText");
mapper.toFirst();
QCOMPARE(readOnlyBox.currentText(), QString("read only item 0"));
QCOMPARE(readWriteBox.currentText(), QString("read write item 0"));
// set some new values on the boxes
readOnlyBox.setCurrentIndex(1);
readWriteBox.setEditText("read write item y");
mapper.submit();
// make sure the new values are in the model
QCOMPARE(model->data(model->index(0, 0)).toInt(), 1);
QCOMPARE(model->data(model->index(0, 1)).toString(), QString("read write item y"));
// now test updating of the widgets
model->setData(model->index(0, 0), 2, Qt::EditRole);
model->setData(model->index(0, 1), QString("read write item z"), Qt::EditRole);
QCOMPARE(readOnlyBox.currentIndex(), 2);
QEXPECT_FAIL("", "See task 125493 and QTBUG-428", Abort);
QCOMPARE(readWriteBox.currentText(), QString("read write item z"));
}
示例13: setEditorData
void ShortcutDelegate::setEditorData(QWidget *editor,
const QModelIndex &index) const {
QString value = index.model()->data(index, Qt::EditRole).toString();
//menu shortcut key
QComboBox *box = qobject_cast<QComboBox*>(editor);
if (box) {
QString normalized=QKeySequence(value).toString(QKeySequence::NativeText);
int pos=box->findText(normalized);
if (pos==-1) box->setEditText(value);
else box->setCurrentIndex(pos);
return;
}
//editor key replacement
QLineEdit *le = qobject_cast<QLineEdit*>(editor);
if (le) {
le->setText(value);
}
}
示例14: setEditorData
//-----------------------------------------------------------------------------
// Function: PortsDelegate::setEditorData()
//-----------------------------------------------------------------------------
void PortsDelegate::setEditorData(QWidget* editor, QModelIndex const& index) const
{
if (index.column() == PortColumns::DIRECTION)
{
QString text = index.data(Qt::DisplayRole).toString();
QComboBox* combo = qobject_cast<QComboBox*>(editor);
int comboIndex = combo->findText(text);
combo->setCurrentIndex(comboIndex);
}
else if (index.column() == PortColumns::TYPE_NAME || index.column() == PortColumns::TYPE_DEF)
{
QString text = index.data(Qt::DisplayRole).toString();
QComboBox* combo = qobject_cast<QComboBox*>(editor);
int comboIndex = combo->findText(text);
// if the text is not found
if (comboIndex < 0)
{
combo->setEditText(text);
}
else
{
combo->setCurrentIndex(comboIndex);
}
}
else if (index.column() == PortColumns::TAG_GROUP)
{
ListEditor* tagEditor = qobject_cast<ListEditor*>(editor);
Q_ASSERT(tagEditor);
QString portTagGroup = index.model()->data(index, Qt::DisplayRole).toString();
if (!portTagGroup.isEmpty())
{
QStringList portTags = portTagGroup.split(", ");
tagEditor->setItems(portTags);
}
}
else
{
ExpressionDelegate::setEditorData(editor, index);
}
}
示例15: setEditorData
void ComboDelegate::setEditorData( QWidget* editor,
const QModelIndex& index ) const {
QString text = index.model()->data(index, Qt::DisplayRole).toString();
QComboBox* combo = qobject_cast<QComboBox*>(editor);
Q_ASSERT(combo);
int rowNumber = combo->findText(text);
// if the current text was not found
if (rowNumber < 0) {
combo->setEditText(text);
}
// if text was found then select it
else {
combo->setCurrentIndex(rowNumber);
}
}