5

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

enter image description here

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 ) 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.
Community
  • 1
  • 1
mosg
  • 12,041
  • 12
  • 65
  • 87
  • Can you describe how you fetch the data from your model? Are you using custom Roles? For example, how would I get 'CompanyName2' for a particular row? – Casey Aug 30 '11 at 16:02
  • For now, I don't have such a solution. Only `QTreeWidget` + my custom widgets. In my Question I'm looking for an answer which will contain the information about joining thing like: table view, models and delegates all together... – mosg Aug 30 '11 at 17:42
  • @mosg it would be a lot easier to answer if you included a full minimal working example in which you want to do X. Frankly, I found the spinbox delegate example very helpful and simple. http://qt-project.org/doc/qt-4.8/itemviews-spinboxdelegate.html. I work in python, so can't help too much with specifics, other than the answer below: it is actually pretty easy--just reimplement paint for a read-only model. The rest of the work goes back to the delegate base class. – eric Dec 11 '14 at 20:07
  • @neuronet Thanks for the reply, but I don't need the answer any more, because it was long-long-long time ago... Truely sad, this UI prototype was terrible, and soon we refused this stuff. – mosg Dec 15 '14 at 13:34

1 Answers1

0

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.

RobbieE
  • 4,280
  • 3
  • 22
  • 36