Qt :(自定义)QWidget的列表,不存在性能问题 [英] Qt: List of (custom) QWidgets without performance problems
问题描述
我现在正在创建Qt应用程序,并且存在以下问题: 我设计了带有一些标签和复选框的自定义QWidget.现在,应用程序应显示自定义QWidget的列表.我尝试了QListWidget,但是对于我的用例来说非常慢.我想添加超过6000个自定义QWidget元素.如果创建这些元素的这些实例并将其添加到QListWidget,则应用程序将崩溃.
I'm right now creating an Qt-application and have following problem: I designed a custom QWidget with some labels and checkboxes. The application should now show a list of the custom QWidgets. I tried the QListWidget but is very slow for my use case. I want to add over 6000 elements of my custom QWidget. If I create these instances of the element and add it to the QListWidget the application will crashed.
哪种方法最适合我的问题?
Which is the best approach for my issue?
非常感谢!
推荐答案
正如其他人所指出的,QListWidget
或QListView
是解决之道.另请注意,您不应使用它显示自定义窗口小部件,请尝试使用自定义 QStyledItemDelegate 而是自己绘制项目.根据您的需要,这可能会很快变得复杂.我已经在这种方法中使用QTableView
并处理了上万个项目,而没有任何性能问题.
As others have noted, QListWidget
or QListView
is the way to go. Also note that you should not display custom widgets with it, try using a custom QStyledItemDelegate instead and draw the items yourself. Depending on what you need, this can get complex really fast. I have used QTableView
with this approach with tenth of thousands of items without performance problems.
如果您确实需要显示自定义窗口小部件,请查看我前一段时间为该确切目的编写的库:
If you really need to display custom widgets, check out a library I wrote some time ago for that exact purpose: longscroll-qt .
这篇关于Qt :(自定义)QWidget的列表,不存在性能问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!