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


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

本文整理汇总了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()
            );
    }
}
开发者ID:VSRonin,项目名称:24TaskSchedule,代码行数:48,代码来源:PICweeklyReportSettings.cpp

示例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;

}
开发者ID:VictorCarlquist,项目名称:GSMESAP,代码行数:28,代码来源:mysqlrelationaldelegate.cpp

示例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;
}
开发者ID:LuisaDomingues,项目名称:subsurface,代码行数:29,代码来源:modeldelegates.cpp

示例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;
}
开发者ID:ursfassler,项目名称:evdraw,代码行数:7,代码来源:ComboboxItemDelegate.cpp

示例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);
}
开发者ID:open-src,项目名称:douml,代码行数:27,代码来源:quickedit.cpp

示例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);
}
开发者ID:open-src,项目名称:douml,代码行数:33,代码来源:quickedit.cpp

示例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;
}
开发者ID:BarsukAlexey,项目名称:xelarogi,代码行数:31,代码来源:handbookdialog.cpp

示例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;
}
开发者ID:NoobSaibot,项目名称:qtcreator-minimap,代码行数:26,代码来源:zoomaction.cpp

示例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;
}
开发者ID:creepydragon,项目名称:r2,代码行数:7,代码来源:QtComboBoxDelegate.cpp

示例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);
}
开发者ID:ErickCastellanos,项目名称:douml,代码行数:32,代码来源:quickedit.cpp

示例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;
}
开发者ID:NoobSaibot,项目名称:qtcreator-minimap,代码行数:8,代码来源:componentaction.cpp

示例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"));
}
开发者ID:Wushaowei001,项目名称:nabavke,代码行数:9,代码来源:pretrazivanjesredstavad1.cpp

示例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;
}
开发者ID:dbinoj,项目名称:subsurface,代码行数:10,代码来源:modeldelegates.cpp

示例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;
}
开发者ID:wulff007,项目名称:FastStorage,代码行数:10,代码来源:wcomboboxdelegate.cpp

示例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;
}
开发者ID:jay602,项目名称:QmlDesignerPlus,代码行数:11,代码来源:numberseriesaction.cpp


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