Looking for guidance on how to approach my "ladder viewer"
-
I’ll do my best to explain what I have going on here. I’m for some general guidance, I’m not sure if I’m headed down the correct path. I am basically a hack, googling my way through this.
I’m creating a ladder logic viewer that mimics the look and feel of a proprietary one that is out there. The proprietary one can export their files as XML, which I parse and try to display in a similar fashion. This is mainly a learning process, I’m not sure if it will ever go anywhere. What I’m trying to avoid, is starting off with the wrong approach and taking it too far, only to have to re-do everything.
I’m attaching 2 pictures, the original software’s ladder view, and what my viewer displays. It’s really proof of concept, there is currently a lot wrong with it. I want to explain my approach, and hopefully get feedback as to how others might approach it. Oh and this is done with pyqt.
The window is basically made up of a ladder window, rungs, instructions. The ladder windows is a QWidget with a vertical layout. It will contain n rungs. A rung is a QWidget with a horizontal layout. From left to right, the rung start, a grid layout (to contain instructions) and an end rung. Each instruction is a QWidget.
The XML gets parsed, the ladder window is generated, each rung is generated with its instructions (placed in the rung grid layout), each rung is placed in the ladder windows vertical layout.
When you look at the original software, does my approach make sense? Some people have suggested that the instructions might be better off being SVG’s or something like that. Are there any other approaches that make sense to anyone?
Messing with layouts took me a long time to get things to look the way they do. How the alignment and stretching worked was a real struggle for me. Size policies, stretch, base sizes, etc. If I had to start over from scratch, I’d be right back on the same struggle bus. It mostly works, though there are some wonky alignment things I still have to work out, like biasing “outputs” (CTU, MOV, TON in my screenshots) to the right side of the window.
image of my attempt: https://postimg.cc/mtfpbyFS
original software image: https://postimg.cc/crR96tRG -
Hi,
I know it's not something you will like to read, but did you consider the Graphics View framework ?
It looks like it could make your life easier.
-
Hi,
I know it's not something you will like to read, but did you consider the Graphics View framework ?
It looks like it could make your life easier.
@SGaist said in Looking for guidance on how to approach my "ladder viewer":
Hi,
I know it's not something you will like to read, but did you consider the Graphics View framework ?
It looks like it could make your life easier.
I've actually seen that page a while back, though I think at the time, I didn't know if it applied to what I was doing.
Not sure if I'll 100% understand it, but I will definitely read it. Being an amateur, sometimes the documentation is a bit fuzzy, I learn by picking apart examples, if you know what I mean.
-
You can use the mouse to interact with objects in a QGraphicsScene given your view allows. This means that you don't necessarily have to mess with integrating QWidgets into your QGraphicsScene setup like I see you might have tried in the screenshot.
^ I misinterpreted the design of your screenshot. Either way, the below still applies, even if not as helpful of a post as it was initially supposed to be.As for the approach as a whole, widgets are straightforward and easy to customize, but they often lack more precise tweaking capability because the style doesn't allow for it. The Graphics View framework is different, but takes less time to learn and will help you in the long run (like what SGaist said).
-
I appreciate the advice. I'll spend some time playing with Graphics View.
Here is what I have currently, shows more of what is going on than the screenshots: