本文整理汇总了C++中QComboBox::setModel方法的典型用法代码示例。如果您正苦于以下问题:C++ QComboBox::setModel方法的具体用法?C++ QComboBox::setModel怎么用?C++ QComboBox::setModel使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类QComboBox
的用法示例。
在下文中一共展示了QComboBox::setModel方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: addShock
void PICWeeklySettings::addShock()
{
QDialog shockDialog;
QDialogButtonBox* dialogBtn = new QDialogButtonBox(QDialogButtonBox::Ok | QDialogButtonBox::Cancel, &shockDialog);
QLabel* ratingLabel = new QLabel(&shockDialog);
ratingLabel->setText(tr("Rating Band"));
QComboBox* ratingCombo = new QComboBox(&shockDialog);
for (int i = 2; i < numRatingBands+2; ++i)
ratingCombo->addItem(m_ShocksModel->headerData(i, Qt::Horizontal).toString());
QLabel* sectorLabel = new QLabel(&shockDialog);
sectorLabel->setText(tr("Sector"));
QComboBox* sectorCombo = new QComboBox(&shockDialog);
sectorCombo->setModel(sectorDelegate->model());
QLabel* geogLabel = new QLabel(&shockDialog);
geogLabel->setText(tr("Country"));
QComboBox* geogCombo = new QComboBox(&shockDialog);
geogCombo->setModel(geographyDelegate->model());
QLabel* shockLabel = new QLabel(&shockDialog);
shockLabel->setText(tr("Shock (bps)"));
QSpinBox* shockSpin = new QSpinBox(&shockDialog);
shockSpin->setRange(0, std::numeric_limits<int>::max());
shockSpin->setValue(0);
shockSpin->setSingleStep(1);
QGridLayout* dialogLay = new QGridLayout(&shockDialog);
dialogLay->addWidget(ratingLabel, 0, 0);
dialogLay->addWidget(ratingCombo, 0, 1);
dialogLay->addWidget(sectorLabel, 1, 0);
dialogLay->addWidget(sectorCombo, 1, 1);
dialogLay->addWidget(geogLabel, 2, 0);
dialogLay->addWidget(geogCombo, 2, 1);
dialogLay->addWidget(shockLabel, 3, 0);
dialogLay->addWidget(shockSpin, 3, 1);
dialogLay->addWidget(dialogBtn, 4, 0, 1, 2);
connect(dialogBtn, &QDialogButtonBox::accepted, &shockDialog, &QDialog::accept);
connect(dialogBtn, &QDialogButtonBox::rejected, &shockDialog, &QDialog::reject);
if(shockDialog.exec()==QDialog::Accepted){
const QModelIndex currPar=m_Shockview->rootIndex();
if (!currPar.isValid())
return;
addScenarioData(
currPar.data().toString()
, geogCombo->currentData().toBool() ? QString(): geogCombo->currentText()
, sectorCombo->currentData().toBool() ? QString() : sectorCombo->currentText()
, ratingCombo->currentData().toBool() ? QString() : ratingCombo->currentText()
, shockSpin->value()
);
}
}
示例2: createEditor
QWidget *mySqlRelationalDelegate::createEditor(QWidget *aParent, const QStyleOptionViewItem &option, const QModelIndex &index) const {
const QSqlRelationalTableModel *sqlModel = qobject_cast<const QSqlRelationalTableModel *>(index.model());
QSqlTableModel *childModel = sqlModel ? sqlModel->relationModel(index.column()) : 0;
if (!childModel )
{
const QSortFilterProxyModel* proxyModel = qobject_cast<const QSortFilterProxyModel *>(index.model());
if (proxyModel)
{
sqlModel = qobject_cast<const QSqlRelationalTableModel *>(proxyModel->sourceModel());
childModel = sqlModel ? sqlModel->relationModel(index.column()) : 0;
}
}
if (!childModel)
{
return QItemDelegate::createEditor(aParent, option, index);
}
QComboBox *combo = new QComboBox(aParent);
combo->setModel(childModel);
combo->setModelColumn(childModel->fieldIndex(sqlModel->relation(index.column()).displayColumn()));
combo->installEventFilter(const_cast<mySqlRelationalDelegate *>(this));
return combo;
}
示例3: createEditor
QWidget* ComboBoxDelegate::createEditor(QWidget* parent, const QStyleOptionViewItem& option, const QModelIndex& index) const
{
QComboBox *comboDelegate = new QComboBox(parent);
comboDelegate->setModel(model);
comboDelegate->setEditable(true);
comboDelegate->setAutoCompletion(true);
comboDelegate->setAutoCompletionCaseSensitivity(Qt::CaseInsensitive);
comboDelegate->completer()->setCompletionMode(QCompleter::PopupCompletion);
comboDelegate->view()->setEditTriggers(QAbstractItemView::AllEditTriggers);
comboDelegate->lineEdit()->installEventFilter( const_cast<QObject*>(qobject_cast<const QObject*>(this)));
comboDelegate->view()->installEventFilter( const_cast<QObject*>(qobject_cast<const QObject*>(this)));
connect(comboDelegate, SIGNAL(highlighted(QString)), this, SLOT(testActivation(QString)));
connect(comboDelegate->lineEdit(), SIGNAL(editingFinished()), this, SLOT(testActivation()));
connect(comboDelegate, SIGNAL(activated(QString)), this, SLOT(fakeActivation()));
currCombo.comboEditor = comboDelegate;
currCombo.currRow = index.row();
currCombo.model = const_cast<QAbstractItemModel*>(index.model());
// Current display of things on Gnome3 looks like shit, so
// let`s fix that.
if (isGnome3Session()) {
QPalette p;
p.setColor(QPalette::Window, QColor(Qt::white));
p.setColor(QPalette::Base, QColor(Qt::white));
comboDelegate->lineEdit()->setPalette(p);
comboDelegate->setPalette(p);
}
return comboDelegate;
}
示例4: QComboBox
QWidget *ComboboxItemDelegate::createEditor(QWidget *parent, const QStyleOptionViewItem &, const QModelIndex &index) const
{
QComboBox *editor = new QComboBox(parent);
editor->setFrame(false);
editor->setModel(modelFromIndex(index));
return editor;
}
示例5: VisibilityDelegateSetup
void QuickEdit::VisibilityDelegateSetup()
{
GenericDelegate* visibilityDelegate = new GenericDelegate(ui->tvEditor, false);
visibilityDelegate->widgetCreator = [&](QWidget * parent)
{
QStringList visibilities = {"public" , "protected", "private", "package", "default"};
QComboBox* box = new QComboBox(parent);
QStringListModel* model = new QStringListModel;
model->setStringList(visibilities);
box->setModel(model);
box->setEditable(false);
return box;
};
visibilityDelegate->dataAccessor = [](QWidget * editor, const QModelIndex & index)
{
QString value = index.model()->data(index, Qt::EditRole).toString();
QComboBox *box = static_cast<QComboBox*>(editor);
box->setCurrentText(value);
};
visibilityDelegate->dataSetter = [](QWidget * editor,QAbstractItemModel* model, const QModelIndex &index)
{
QComboBox * box = static_cast<QComboBox*>(editor);
QString value = box->currentText();
model->setData(index, value, Qt::EditRole);
};
ui->tvEditor->setItemDelegateForColumn(columns.indexOf("visibility"), visibilityDelegate);
}
示例6: PrefixDelegateSetup
void QuickEdit::PrefixDelegateSetup()
{
GenericDelegate* delegate = new GenericDelegate(ui->tvEditor, false);
delegate->widgetCreator = [&](QWidget * parent)
{
QStringList list;
list << " " << "const " << "volatile ";
QCompleter *completer = new QCompleter(list, parent);
completer->setCaseSensitivity(Qt::CaseSensitive);
QComboBox* box = new QComboBox(parent);
QStringListModel* model = new QStringListModel;
model->setStringList(list);
box->setModel(model);
box->setEditable(true);
box->setCompleter(completer);
return box;
};
delegate->dataAccessor = [](QWidget * editor, const QModelIndex & index)
{
QString value = index.model()->data(index, Qt::EditRole).toString();
QComboBox *box = static_cast<QComboBox*>(editor);
box->setCurrentText(value);
};
delegate->dataSetter = [](QWidget * editor,QAbstractItemModel* model, const QModelIndex &index)
{
QComboBox * box = static_cast<QComboBox*>(editor);
QString value = box->currentText();
model->setData(index, value, Qt::EditRole);
};
ui->tvEditor->setItemDelegateForColumn(columns.indexOf("prefix"), delegate);
}
示例7: if
QWidget *MySqlRelationDelegate::createEditor(QWidget *aParent, const QStyleOptionViewItem &option, const QModelIndex &index) const
{
const QSqlRelationalTableModel *sqlModel = qobject_cast<const QSqlRelationalTableModel *>(index.model());
QSqlTableModel *childModel = sqlModel ? sqlModel->relationModel(index.column()) : 0;
if (!childModel)
{
if (HandbookDialog::m_record.fieldName(index.column()).contains("IS_", Qt::CaseSensitive))
{
QCheckBox * checkBox = new QCheckBox(aParent);
checkBox->setChecked(index.data().toInt() > 0);
return checkBox;
}
else if (HandbookDialog::m_record.fieldName(index.column()).contains("DATE_", Qt::CaseSensitive))
{
QDateEdit * dateEdit = new QDateEdit(aParent);
dateEdit->setDate(QDate::fromString(index.data().toString(), "yyyy-MM-dd"));
return dateEdit;
}
else
{
return QItemDelegate::createEditor(aParent, option, index);
}
}
QComboBox *combo = new QComboBox(aParent);
combo->setModel(childModel);
combo->setModelColumn(childModel->fieldIndex(sqlModel->relation(index.column()).displayColumn()));
combo->installEventFilter(const_cast<MySqlRelationDelegate *>(this));
return combo;
}
示例8: QComboBox
QWidget *ZoomAction::createWidget(QWidget *parent)
{
QComboBox *comboBox = new QComboBox(parent);
if (m_comboBoxModel.isNull()) {
m_comboBoxModel = comboBox->model();
comboBox->addItem("10 %", 0.1);
comboBox->addItem("25 %", 0.25);
comboBox->addItem("50 %", 0.5);
comboBox->addItem("100 %", 1.0);
comboBox->addItem("200 %", 2.0);
comboBox->addItem("400 %", 4.0);
comboBox->addItem("800 %", 8.0);
comboBox->addItem("1600 %", 16.0);
} else {
comboBox->setModel(m_comboBoxModel.data());
}
comboBox->setCurrentIndex(3);
connect(comboBox, SIGNAL(currentIndexChanged(int)), SLOT(emitZoomLevelChanged(int)));
connect(this, SIGNAL(indexChanged(int)), comboBox, SLOT(setCurrentIndex(int)));
comboBox->setProperty("hideborder", true);
return comboBox;
}
示例9: createEditor
QWidget* QtComboBoxDelegate::createEditor(QWidget* parent, const QStyleOptionViewItem& option,
const QModelIndex& index) const
{
QComboBox* editor = new QComboBox(parent);
editor->setModel(m_model);
return editor;
}
示例10: DirectionDelegateSetup
void QuickEdit::DirectionDelegateSetup()
{
GenericDelegate* delegate = new GenericDelegate(ui->tvEditor, false);
delegate->widgetCreator = [](QWidget* parent)
{
QStringList visibilities;
visibilities << "inout" << "in" << "out";
QComboBox* box = new QComboBox(parent);
QStringListModel* model = new QStringListModel;
model->setStringList(visibilities);
box->setModel(model);
box->setEditable(false);
return box;
};
delegate->dataAccessor = [](QWidget* editor, const QModelIndex& index)
{
QString value = index.model()->data(index, Qt::EditRole).toString();
QComboBox* box = static_cast<QComboBox*>(editor);
box->setCurrentText(value);
};
delegate->dataSetter = [](QWidget* editor, QAbstractItemModel* model, const QModelIndex& index)
{
QComboBox* box = static_cast<QComboBox*>(editor);
QString value = box->currentText();
model->setData(index, value, Qt::EditRole);
};
ui->tvEditor->setItemDelegateForColumn(columns.indexOf("direction"), delegate);
}
示例11: QComboBox
QWidget *ComponentAction::createWidget(QWidget *parent)
{
QComboBox *comboBox = new QComboBox(parent);
comboBox->setModel(m_componentView->standardItemModel());
connect(comboBox, SIGNAL(currentIndexChanged(int)), SLOT(emitCurrentComponentChanged(int)));
return comboBox;
}
示例12: QSqlQueryModel
void PretrazivanjeSredstavaD1::setModelGodina()
{
QComboBox *view = ui->cbGodina;
modelGodina = new QSqlQueryModel();
modelGodina->setQuery("select 'Sve' union select distinct(substr(datum, -4)) as godina from spisak order by godina;");
view->setModel(modelGodina);
view->setModelColumn(0);
view->setCurrentIndex(view->findText("Sve"));
}
示例13: createEditor
QWidget* ComboBoxDelegate::createEditor(QWidget* parent, const QStyleOptionViewItem& option, const QModelIndex& index) const
{
QComboBox *comboDelegate = new QComboBox(parent);
comboDelegate->setModel(model);
comboDelegate->setEditable(true);
comboDelegate->setAutoCompletion(true);
comboDelegate->setAutoCompletionCaseSensitivity(Qt::CaseInsensitive);
comboDelegate->completer()->setCompletionMode(QCompleter::PopupCompletion);
return comboDelegate;
}
示例14: QComboBox
QWidget *wComboBoxDelegate::createEditor(QWidget *parent,
const QStyleOptionViewItem &/* option */,
const QModelIndex &/* index */) const
{
QComboBox *editor = new QComboBox(parent);
editor->setModel(modelData);
editor->setModelColumn(modelIndexValue);
return editor;
}
示例15: QComboBox
QWidget *NumberSeriesAction::createWidget(QWidget *parent)
{
QComboBox *comboBox = new QComboBox(parent);
comboBox->setModel(m_comboBoxModel.data());
comboBox->setCurrentIndex(m_comboBoxModelIndex);
connect(comboBox, SIGNAL(currentIndexChanged(int)), SLOT(emitValueChanged(int)));
return comboBox;
}