gpt4 book ai didi

qt - 适用于大型模型的 QCompleter

转载 作者:行者123 更新时间:2023-12-02 06:19:40 25 4
gpt4 key购买 nike

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

最佳答案

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

调整组合:

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());
}

调整下拉/弹出窗口( View ):

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());
}

关于qt - 适用于大型模型的 QCompleter,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33447843/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com