如何使用自定义(不可编辑)委托创建模型/视图 QTableView?
这是我想要得到的(这是一个 QTableView
小部件 + MVC 基于 QAbstractTableModel
和多个 委托 > ):
注释:
代表不担任编辑者,他们是仅限观众!我无法使用此表格视图编辑模型。
委托必须是可实现的。这意味着蓝色行的所有总高度可以是 25px 或 250px。
MV 是简单的数据:
1ROW:CompanyName1 Name1、Name2、Name3 其他数据
2ROW:CompanyName2 SingleName1 其他数据
3ROW: CompanyName3 Name1,Name2 OTHER DATA 等等...
问题:
- 是否可以创建自定义委托(
QItemDelegate
,或QStyleItemDelegate
),例如,到第二列,如上图所示?如果可能的话,也许你可以给我一些例子,或者资源链接,我可以在哪里查看它们。
附言。是的,我已经查看了所有带有委托的 Qt Demo 示例,但我就是不明白,如何做我想做的事。
附言。 QTableView
-> setIndexWidget()
我认为这不是一个好主意。但是 QTableView
->setItemDelegateForColumn( myCustomDelegate )
方法更好!
P3S。我不是在寻找 QTableWidget
类的解决方案...
谢谢您的回复! :-)
更新#1:
我认为:
委托仅用于编辑(例如,如果我们正在使用模型/视图对象)和管理类似的项目(所有/仅列/仅行)。
自定义小部件更好,但我还没有在免费的 Qt 项目中遇到它们。而且要获得此类小部件的良好且正确的代码并不容易......
补充:
- 这里是链接到相似性问题。
Here is what I'm trying to get ( this is a QTableView
widget + MVC based on QAbstractTableModel
with multiply delegates ):
Notes:
Delegates a not working as editors, they are ONLY viewers! I'm not getting to edit model with this table view.
Delegates must be realizable. It means that all total height of the BLUE row could be 25px, or 250px.
MV is simple data:
1ROW: CompanyName1 Name1,Name2,Name3 OTHER DATA
2ROW: CompanyName2 SingleName1 OTHER DATA
3ROW: CompanyName3 Name1,Name2 OTHER DATA and so on...
Question:
- Is it possible to create custom delegate (
QItemDelegate
, orQStyleItemDelegate
), for example, to the 2nd column like on the image above? And if it's possible, maybe you could give me some examples, or resource links where can I look at them.
PS. Yes, I have looked at all Qt Demo examples with delegates, but I just don't get it, how to do what I want.
PSS. QTableView
-> setIndexWidget()
I think that is not a good idea. But QTableView
->setItemDelegateForColumn( myCustomDelegate )
methods are better!
P3S. I'm not looking solution for QTableWidget
class...
Thank you for your replies! :-)
Update #1:
I think that:
Delegates are used only for edits (for example, if we are working with model/view object) and manage similar items (all/just column/just row).
Custom widgets are better, but I have not meet them in free Qt projects. And it's not too easy to get the nice and correct code of such kind of widgets...
Addition:
- Here is link to similarity question.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
委托不仅可用于创建编辑中使用的小部件。它们还用于创建每个可见索引(在本例中为表格单元格)的整体外观。
您可以通过重新实现 paint() 方法。
Delegates are not only useful for creating widgets used in editing. They are also used in creating the overall look and feel of each visible index (in this case, a table cell).
You can custom create the look and feel by reimplementing the paint() method of the delegate.