本文整理汇总了C++中QComboBox::setCompleter方法的典型用法代码示例。如果您正苦于以下问题:C++ QComboBox::setCompleter方法的具体用法?C++ QComboBox::setCompleter怎么用?C++ QComboBox::setCompleter使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类QComboBox
的用法示例。
在下文中一共展示了QComboBox::setCompleter方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: 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);
}
示例2: TypeDelegateSetup
void QuickEdit::TypeDelegateSetup()
{
GenericDelegate* delegate = new GenericDelegate(ui->tvEditor, false);
delegate->widgetCreator = [](QWidget* parent)
{
BrowserNodeList result;
QStringList classes;
BrowserClass::instances(result);
result.full_names(classes);
QStringList basics = GenerationSettings::basic_types();
classes+=basics;
QCompleter* completer = new QCompleter(classes, parent);
completer->setCaseSensitivity(Qt::CaseSensitive);
QComboBox* box = new QComboBox(parent);
QStringListModel* model = new QStringListModel;
model->setStringList(classes);
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("type"), delegate);
}
示例3: createToolbar
void FinanceMgr::createToolbar()
{
QToolBar* toolBar = addToolBar(QString::fromLocal8Bit("系统工具"));
QAction* calcAction = new QAction(QIcon(tr(":/Icon/Resources/calculator.png")), QString::fromLocal8Bit("计算器"), this);
toolBar->addAction(calcAction);
connect(calcAction, SIGNAL(triggered()), this, SLOT(openCalc()));
ui.toolBar->addWidget(new QLabel(QString::fromLocal8Bit("年月: "), this));
QComboBox* yearMonth = new QComboBox(this);
QStringList dateList;
// find the most faraway month from the budget table
Database_Result& dr = DatabaseHandler::instance()->getHandler()->from(BudgetTableName)->limit("1")->orderBy("budget_month ASC")->get();
int currentYear = QDate::currentDate().year();
QString strCurrentYear = QString("%1").arg(currentYear);
int currentMonth = QDate::currentDate().month();
QString strCurrentMonth = QString("%1").arg(currentMonth);
QString strYM = QString("%1%2").arg(strCurrentYear, strCurrentMonth);
QDate databaseDate = QDate::currentDate();
if (dr.count() > 0)
{
Array record = *dr.resultArray().begin();
databaseDate = QDate::fromString(record[budgetMonthColumnName].c_str(), Qt::ISODate);
}
// create the year month list from the database time to current time
bool loop = true;
int year, month;
year = databaseDate.year();
month = databaseDate.month();
do
{
QString strYear = QString("%1").arg(year);
QString strMonth = QString("%1").arg(month);
QString strYear2Month = QString("%1%2").arg(strYear, strMonth);
dateList << strYear2Month;
month++;
if (month > 12)
{
month = 1;
year++;
}
// add more than 2 month to the list
int monthCount1 = year * 12 + month;
int monthCount2 = QDate::currentDate().year() * 12 + QDate::currentDate().month();
if ((monthCount2 + 2) < monthCount1)
{
loop = false;
}
} while (loop);
yearMonth->addItems(dateList);
yearMonth->setEditable(true);
QCompleter* ymCompleter = new QCompleter(dateList, this);
yearMonth->setCompleter(ymCompleter);
yearMonth->setEditText(strYM);
ui.toolBar->addWidget(yearMonth);
connect(yearMonth, SIGNAL(editTextChanged(const QString&)), this, SLOT(handleMonthChanged(const QString&)));
}