MVVM pattern with PySide
Asked Answered
G

3

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.

Glaucescent answered 14/6, 2012 at 22:22 Comment(1)
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.Auramine
J
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.

Jigging answered 4/9, 2013 at 23:53 Comment(0)
P
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.

Proteiform answered 8/9, 2013 at 8:33 Comment(0)
E
-3

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.

Encratia answered 21/6, 2013 at 3:38 Comment(1)
When you pass around view models in c#/MVC is basically a MVVM system. These are just constructs/patterns.Jigging

© 2022 - 2024 — McMap. All rights reserved.