[PyQt] QML types registered as QtQuickItems not following Row/Column positioning

Louis Simons lousimons at gmail.com
Tue Jan 3 18:29:07 GMT 2017


Hi Scott,

I think I've probably committed on top of it since then, since I didn't
hear back from anyone, sorry.  I wasn't aware about specifying
fillWdith/fillHeight and will keep that in mind.

I'm in the middle of a huge refactor that I think will dodge the issue.  My
PyQt5 app has minimal business logic and only handles the front-end by
receiving JSON models over ZMQ from a separate Python back-end.  The PyQt5
client sends action messages back over ZMQ, and the back-end pushes new
model data.  This way, if the front-end closes or crashes, the back-end
state persists.

In the refactor, I'm going to make a QML object backed by a Python class
called the Store that will handle receiving new JSON data over ZMQ.  Then
the models will be list properties of the Store, which can be passed to all
the other components in the app.  Does this seem feasible?  I think It has
the benefit of letting me pass around models almost entirely in QML and
keeps all my low level data model updates in one place.  It is similar to
the architecture presented at
https://medium.com/@benlaud/qml-application-architecture-guide-with-flux-b4e970374635#.x7mtwhjnh,
and is similar to some other client-side web frameworks.

Thanks,
Louis

On Tue, Jan 3, 2017 at 11:35 AM Cody Scott <cody at perspexis.com> wrote:

Where is the QML code that is not working? I think you might just be having
a problem with layout in QML. One thing to note is that by default
components don't have a width and a height so you need to either specify
them directly or with Layout.fillWidth: true

On Thu, Dec 22, 2016 at 9:58 PM, Louis Simons <lousimons at gmail.com> wrote:

I've been learning (mostly trial and error) PyQt5 with a project at
https://github.com/superlou/snowman-qt-client.  I've tried to do the view
layer in QML, with components that need a model backend defined in Python
and registered.  For example, the MainBus QML type is registered as a
MainBus Python class.  The MainBus Python object then handles some business
logic communication to the backend server.  The only gotcha I'm running
into is that it seems like the custom QML items extending QtQuickItems
don't get positioned properly using layouts or anchors.  I can set x and y
positions on them, but that's about it.

Is this expected behavior?  I'm starting to think that maybe the intent of
registering types is not to directly link a QML "view" to a Python "model."
 Is there a more appropriate way to create this kind of architecture?
Would it be more appropriate to create a MainBusModel class, that's used
purely as a property of a QML MainBus view?  Another part of me is thinking
that I missed the boat altogether, and that my registered type should
really be the ManagerConnection (
https://github.com/superlou/snowman-qt-client/blob/master/manager_connection.py),
which is really what the Python object is interacting with, and almost all
of my logic could be handled in QML.

I apologize if this is a basic question.  I've been reading the C++
documentation, and while it says "how" to do things, it doesn't really
recommend how you structure these kinds of apps.

_______________________________________________
PyQt mailing list    PyQt at riverbankcomputing.com
https://www.riverbankcomputing.com/mailman/listinfo/pyqt
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://www.riverbankcomputing.com/pipermail/pyqt/attachments/20170103/a473323c/attachment.html>


More information about the PyQt mailing list