Qt 大型模型的QCompleter

Qt 大型模型的QCompleter,qt,model,qcompleter,large-data,Qt,Model,Qcompleter,Large Data,QCompleter在大数据集(大型号)上的工作速度稍慢:当我开始在QCombobox中输入字符时,几秒钟后会显示带有变体的自动完成弹出窗口,当输入第二个字符时QCompleter在几秒钟内也不会对按键做出反应。接下来的角色很好。模型大小约为100K记录。是否有可能提高QCompleter性能或在第二个或第三个输入符号后显示弹出窗口?有一些很好的例子吗?解决方案似乎与此类似:asQCompleter在其弹出()中也使用QListView。因此,加速QCombobox的完整解决方案是: 调整组合:

QCompleter
在大数据集(大型号)上的工作速度稍慢:当我开始在
QCombobox
中输入字符时,几秒钟后会显示带有变体的自动完成弹出窗口,当输入第二个字符时
QCompleter
在几秒钟内也不会对按键做出反应。接下来的角色很好。模型大小约为100K记录。是否有可能提高
QCompleter
性能或在第二个或第三个输入符号后显示弹出窗口?有一些很好的例子吗?

解决方案似乎与此类似:as
QCompleter
在其
弹出()中也使用
QListView
。因此,加速QCombobox的完整解决方案是:

调整组合: 调整下拉列表/弹出窗口(视图): 调整完成器:
你用什么型号的?如果可能,您需要改进模型的性能。我使用
QStandardItemModel
。如何提高其性能?我尝试对它进行预排序,以设置灵敏度,就像Qt-doc所说的:
combo->completer()->setCaseSensitive(Qt::CaseSensitive);combo->completer()->setModelSorting(QCompleter::CaseSensitivelySortedModel)我还能做什么?您可以基于
qabstractemmodel
创建自己的模型。两个对您有用的链接:不,
QStandardItemModel
在这里就足够了,请看下面的答案。
void ComboboxTools::tweak(QComboBox *combo)
{
  //  For performance reasons use this policy on large models
  // or AdjustToMinimumContentsLengthWithIcon
  combo->setSizeAdjustPolicy(QComboBox::AdjustToMinimumContentsLength);

  // Improve combobox view performance
  tweak((QListView *)combo->view());

  // Improve combobox completer performance
  tweak(combo->completer());
}
void ComboboxTools::tweak(QListView *view)
{
  // Improving Performance:  It is possible to give the view hints
  // about the data it is handling in order to improve its performance
  // when displaying large numbers of items. One approach that can be taken
  // for views that are intended to display items with equal sizes
  // is to set the uniformItemSizes property to true.
  view->setUniformItemSizes(true);
  // This property holds the layout mode for the items. When the mode is Batched,
  // the items are laid out in batches of batchSize items, while processing events.
  // This makes it possible to instantly view and interact with the visible items
  // while the rest are being laid out.
  view->setLayoutMode(QListView::Batched);
  // batchSize : int
  // This property holds the number of items laid out in each batch
  // if layoutMode is set to Batched. The default value is 100.
  // view->setBatchSize(100);
}
void ComboboxTools::tweak(QCompleter *completer)
{
  completer->setCaseSensitivity(Qt::CaseInsensitive);
  // If the model's data for the completionColumn() and completionRole() is sorted
  // in ascending order, you can set ModelSorting property
  // to CaseSensitivelySortedModel or CaseInsensitivelySortedModel.
  // On large models, this can lead to significant performance improvements
  // because the completer object can then use a binary search algorithm
  // instead of linear search algorithm.
  completer->setModelSorting(QCompleter::CaseSensitivelySortedModel);

  // Improve completer popup (view) performance
  tweak((QListView *)completer->popup());
}