本文整理汇总了C++中QCompleter::completionModel方法的典型用法代码示例。如果您正苦于以下问题:C++ QCompleter::completionModel方法的具体用法?C++ QCompleter::completionModel怎么用?C++ QCompleter::completionModel使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类QCompleter
的用法示例。
在下文中一共展示了QCompleter::completionModel方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: QMainWindow
//.........这里部分代码省略.........
completer->setModel(playerTableModel);
completer->setCompletionColumn(PlayerTableModel::COLUMN_NAME);
completer->setFilterMode(Qt::MatchContains);
completer->setCaseSensitivity(Qt::CaseInsensitive);
// Select
auto HighlightPlayerInTable = [=](const QModelIndex& srcIdx)
{
// Lookup catergory
auto catergoryIdx = srcIdx.model()->index(srcIdx.row(), PlayerTableModel::COLUMN_CATERGORY);
auto catergory = srcIdx.model()->data(catergoryIdx).toUInt();
// Change to tab
hitterPitcherTabs->setCurrentIndex(CaterogyToTab(catergory));
// Select row
if (catergory == Player::Catergory::Hitter) {
auto proxyModel = dynamic_cast<QSortFilterProxyModel*>(hitterTableView->model());
auto proxyIdx = proxyModel->mapFromSource(srcIdx);
hitterTableView->selectRow(proxyIdx.row());
hitterTableView->setFocus();
} else if (catergory == Player::Catergory::Pitcher) {
auto proxyModel = dynamic_cast<QSortFilterProxyModel*>(pitcherTableView->model());
auto proxyIdx = proxyModel->mapFromSource(srcIdx);
pitcherTableView->selectRow(proxyIdx.row());
pitcherTableView->setFocus();
}
};
// Select the target
connect(completer, static_cast<void (QCompleter::*)(const QModelIndex&)>(&QCompleter::activated), [=](const QModelIndex& index) {
// Get player index
QAbstractProxyModel* proxyModel = dynamic_cast<QAbstractProxyModel*>(completer->completionModel());
auto srcIdx = proxyModel->mapToSource(index);
// Highlight this player
HighlightPlayerInTable(srcIdx);
});
// Search widget
QLineEdit* playerSearch = new QLineEdit(this);
playerSearch->setCompleter(completer);
// Main toolbar
QToolBar* toolbar = new QToolBar("Toolbar");
toolbar->addWidget(new QLabel(" Status: ", this));
toolbar->addActions(QList<QAction*>{filterDrafted, filterReplacement});
toolbar->addSeparator();
toolbar->addWidget(new QLabel(" Leagues: ", this));
toolbar->addActions(QList<QAction*>{filterAL, filterNL, filterFA});
toolbar->addSeparator();
toolbar->addWidget(new QLabel(" Positions: ", this));
toolbar->addActions(QList<QAction*>{filterStarter, filterRelief});
toolbar->addActions(QList<QAction*>{filterC, filter1B, filter2B, filterSS, filter3B, filterOF, filterCI, filterMI, filterDH, filterU});
toolbar->addWidget(spacer);
toolbar->addWidget(new QLabel("Player Search: ", this));
toolbar->addWidget(playerSearch);
toolbar->setFloatable(false);
toolbar->setMovable(false);
QMainWindow::addToolBar(toolbar);
// Helper to adjust filters
auto ToggleFilterGroups = [=](int index)
{