首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >大型模型的QCompleter

大型模型的QCompleter
EN

Stack Overflow用户
提问于 2015-10-31 03:48:32
回答 1查看 1.8K关注 0票数 2

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

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2015-10-31 17:09:10

解决方案看起来与此类似:https://stackoverflow.com/a/33404207/630169作为QCompleter也在其popup()中使用QListView。因此,加速解决方案的QCombobox是:

调整组合:

代码语言:javascript
复制
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());
}

调整下拉/弹出(视图):

代码语言:javascript
复制
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);
}

调整完成者:

代码语言:javascript
复制
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());
}
票数 8
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/33447843

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档