0
votes

Can I create some custom view? I have some model(written in C++ inheriting QAbstractListModel), which I use in ListView and GridView. When I do some changes in C++, I can just emit dataChanged signal to update my views. Can I connect some QML properties to data from model? Image.source for example?

EDIT 1

I have QAbstractListModel subclass. It contains data about some files. I have created ListView in the left of my main window. Click on some row should change view in the right working area. Working area contains detailed information about each file. So, how can I implement this?

1
It sounds like what you ant to do should be mostly documented here apart from the bit about showing information in another view but that could be handled with a MouseArea in your ListView delegate and handling the onClicked - sjdowling
@sjdowling Yes, I've already read this :) I have MouseArea in my delegate and onClicked I save index and change state of right view. It gets information (file_name, size, etc.) from MyMainModel which I use for left list. When some changes are happened interactively with a model, left ListView is changed according to them after emitting dataChanged. But right view, which is not GridView or ListView, doesn't change and I should use something like Connections QML element and emit some myParamChanged from C++. - VALOD9
Using a plain item and bind it to the delegate properties is not an option? As you select a new current item also the values changes and if a change occurs in the model underneath, also the values changes accordingly. - BaCaRoZzo

1 Answers

0
votes

You can access whatever part of your C++ class you expose as a property:

class MyModel : public QAbstractListModel
{    
    Q_OBJECT
    Q_PROPERTY(QString source READ source WRITE setsource  NOTIFY source Changed)
public:
    QString source();
    void setSource(QString s);
signals:
    void sourceChanged();
};

Register the type:

qmlRegisterType<MyModel>("Stuff", 1, 0, "MyModel");
MyModel model
QQmlContext *ctxt = rootContext();
ctxt->setContextProperty("myModel", &model);

Then in QML:

import Stuff 1.0

Image {
    source: myModel.source
}