0

how can I check what is displayed on the listView? More generally I need region occupied by those displayed item so I can paint another item below them.

smallB
  • 16,662
  • 33
  • 107
  • 151
  • What exactly do you mean with the "region occupied by those displayed items"? You want to add an item in the list view or draw something below the list view? – pnezis Mar 17 '12 at 12:37
  • @webclectic I want to add an item to the listView – smallB Mar 17 '12 at 12:39

1 Answers1

0

If you need to add an item to the listview then you don't have to write any specific code for this. The list view contains the items of your model.

A QListView presents items stored in a model, either as a simple non-hierarchical list, or as a collection of icons. This class is used to provide lists and icon views that were previously provided by the QListBox and QIconView classes, but using the more flexible approach provided by Qt's model/view architecture.

Once the model items change a signal is emitted from the model and the view is repainted in order to display the modified items.

For more details check how the model/view programming in Qt works.

pnezis
  • 12,023
  • 2
  • 38
  • 38
  • I know that, but I need to plug in my own delegate, reason explained in here:http://stackoverflow.com/questions/9749160/using-qt-itemdelegate, that's why I need to know where to paint next item. – smallB Mar 17 '12 at 12:48
  • You just add your delegate to the listview using `setItemDelegate`. The only difference is that the delegate is used for the display of the items. In the paint of the delegate you just define how a single item will be painted. You dont need to care about its position. – pnezis Mar 17 '12 at 12:53
  • but in the paint fnc surely I have to use drawText fnc? and this fnc needs either point, rect, or x and y, or am I missing something (I believe that I do) – smallB Mar 17 '12 at 12:57
  • You draw on the rect which is given by the `QStyleOptionViewItem`, the second argument of the `paint` function. Check this answer for sample code: http://stackoverflow.com/questions/5334590/using-a-qstyleditemdelegate-on-a-qlistview-with-qsqlquerymodel – pnezis Mar 17 '12 at 13:00
  • thanks, would you mind telling me how to (on this same line) draw checkBox, so this line of text could be un/checked? – smallB Mar 17 '12 at 13:04
  • Its better to use a proxy model for that. For more details check this: http://qt-project.org/wiki/QSortFilterProxyModel_subclass_to_add_a_checkbox – pnezis Mar 17 '12 at 13:13
  • thanks, I have already proxy model in place yet no checkboxes are shown, would you know why? – smallB Mar 17 '12 at 13:16
  • what I meant by my last comment is that before I've plugged in my own delegate checkboxes are correctly displayed, but with my delegate they are not. – smallB Mar 17 '12 at 13:28