16

I've been trying to find a way to implement MVVM with PySide but haven't been able to. I think that there should be a way to create Views from ViewModels with QItemEditorFactory, and to do data binding I think I can use QDataWidgetMapper.

Do you have any ideas on how MVVM may be implemented with Qt and PySide? Even if there are some resources in C++ I'll try to translate them to python.

Thanks.

Jorge Vargas
  • 1,035
  • 12
  • 24
  • How on Earth did I miss `QDataWidgetMapper` I don't know. I ended up implementing one myself. Somehow, in all of my exploration of Qt documentation and sources, I've stayed blind to it. Although my mapper is a bit different; it lets one map an arbitrary index to a widget, there's no notion of a current row/column. – Kuba hasn't forgotten Monica Sep 08 '13 at 08:34

3 Answers3

1

MVVM was a specialization of the MVP (Model-View-Presenter) pattern, and is not specifically unique to WPF, but was part of its inception. I think what you're trying to get at is an MVP to expose your domain model as a view into that domain.

If you want examples in c++, you can see this PDF. However, you can get the gist of it from a terse synopsis in manged c# below:

public class DomainView : IDomainView
{
    private IDomainPresenter domainPresenter = null;

    ///<summary>Constructor</summary>
    public DomainView()
    {
        domainPresenter = new ConcreteDomainPresenter(this);
    }
}

Also, I'm wondering you could use the abstract object notation to make passable generics (view models) from your model to your views. Basically, you'd need an intermediary function to flag the relevant parts to serialize.

FlavorScape
  • 9,743
  • 9
  • 66
  • 111
0

I don't know how far do you want to take MVVM, but at a basic level it comes with Qt, and I've been using it for a long time. You have a business-specific model, say tied to a database. Then you create view-specific viewmodel as a proxy model. You can stack a few layers of those, depending on what you need. Then you show that using a view. As long as everything is set up right, it will "just work". Now if you want to use a model to configure a view, Qt doesn't provide anything directly for you. You'd need to write a factory class that can use viewmodel data to instantiate and set up the view for you. Everything depends on how far do you want to take it, and what architectural benefits does it give you.

Kuba hasn't forgotten Monica
  • 88,505
  • 13
  • 129
  • 275
-2

An obvious answer for me is that MVVM is suitable for WPF and some other techs that welcome this pattern, and so you have to find out whether it's possible to apply this pattern on other technologies. Please, read on MVVM in wiki.

HichemSeeSharp
  • 3,055
  • 2
  • 16
  • 44