开发者

HowTo create model/view QTableView with custom (non-editable) delegates?

Here is what I'm trying to get ( this is a QTableView widget + MVC based on QAbstractTableModel with multiply delegates ):

HowTo create model/view QTableView with custom (non-editable) 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, or QStyleItemDelegate), 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 ) 开发者_C百科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.


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜