0

I have connected QML's ListView to my C++ model and it updates when model changes which is cool. However I don't want to display my data in ListView bur rather in custom way in rectangle (ideally a plain view which doesn't exist).

How could I do this?

The issue I see obviously is rectangle is not a view and there is other plain view which allows custom drawing. Is there way around it?

Addon

Following up on the answer and comment, let me give context why I am doing it. I have various information and if I use list, I will have to use multiple lists on one screen which doesn't look good. What I want to implement is what I would call 'document view'. Header goes here, title goes there, data here and footer here. It is a custom presentation of my model's data.

@Folibis, I like your first point. It seems like if do something like:

Rectangle 
{
   Text { text: mySingleton.getFruitName() }
   Text { text: mySingleton.getFruitPrice() }
}

Note I have intentionally not included anchors or geometry to keep focus on my question but assume price appears next to fruit name.

Does this mean if I update fruit name or price of the exact same object in model else where in GUI, the above will be updated automatically?

zar
  • 11,361
  • 14
  • 96
  • 178
  • You can use a `Flickable` with a `Repeater` as model if you don't want to use a `ListView` (see [here](http://stackoverflow.com/questions/26669856/howto-flick-a-qml-listview-horizontal-and-vertical/26840056#26840056)). You still have the `delegate` for the model items and the flicking ability without `ListView` features. Howeer the question is: what's the reason to not use `ListView`? – BaCaRoZzo Jan 21 '15 at 13:30

1 Answers1

0

You have several ways to implement custom drawing. I can't really imagine what data can be supplied to Rectangle but anyway:

  1. You can create custom Item in C++, for example singleton an fetch needed data from it.
Rectangle {
    width: mySingleton.getWidth();
    height: mySingleton.getHeight();
    color: mySingleton.getColor();
}
  1. You can create custom element derived from QQuickPaintedItem. All you need is reimplement QQuickPaintedItem::​paint(QPainter * painter) to draw your own rectangle. It's simpliest way to create ow element but not efficient since it uses QPainter.

  2. Create custom element deriver from QQuickItem. You will need to reimplement QSGNode * QQuickItem::​updatePaintNode(QSGNode * oldNode, UpdatePaintNodeData * updatePaintNodeData). That's fast and reliable way but requires OpenGL experience.

  3. Also as (1), but painting on Canvas element

folibis
  • 12,048
  • 6
  • 54
  • 97