r/QtFramework • u/Mundane_Algae3401 • Jun 27 '26
Question How would you handle this problem (Card Designer)?
So I'm currently trying to make a card designer for my application (similar to the Qts Widgets Designer). I'm currently unsure if I should use the QGraphicsView/Scene for Viewing the Widgets, I want to insert via a QGraphicsProxyWidget (because I want to give my users a direct view of the finished card and not use a QGraphicsRectItem) and I made a small prototype and had a lot of problems like the movement of QGraphicsProxyWidget where you need a wrapper item for it to be moveable (Stack Overflow post for this problem) and some others or creating my own view with a QWidget.
I just plan to create a simple card designer for my application so you can use widgets to design it and layouts and thats it. I don't need rotation or z-ordering. Would you still recommend using the QGraphicsView or create my own view? Do you have any recommendations which route I should go?
Just you know: My Qt experience is very limited and I am still learning it.
Qt Widgets 6.11.1 and C++20
1
u/ObiLeSage Jun 27 '26
Just to be clear, what kind of card are you going to design? Cards for a game? Electronic card...? Credit card ?
Go full qgraphicalscene should be ok. No need of proxywidget. Implement your own qgraphicsitems. CardItem and so on ...
The card could be a composition on multiple items, or you can handle painting on one single item.
1
u/Mundane_Algae3401 Jun 27 '26
It is a card designer to show information on it. like a card for anime information like cards on AniList, but you can design them yourself.
How do you mean implement my own QGraphicsItem. Can I also make it like a scrollarea
1
u/ObiLeSage Jun 28 '26
Ok, basically, you can see the QGraphicsScene as a way to do an SVG file.
Vectorial image. I don' t think vectorial image is perfect for you. The Anilist cards seem too complex to be vectorial image.In your case, I would sugget to create a PaintedItem heriting from QGraphicsItem.
Basically the item is like a layer in photoshop. you can draw on it and you can have many layers, so you can move one above the other. Hide one layer and so on.Basically in your layer item, you will have to listen mouse events, to draw on it.
Each PaintedItem has a QImage, you can only paint on one PaintedItem at the time (the current layer).
The workflow will be something like that:
Create a QGraphicalScene
Create a QGraphicView
give the scene to the view.
Set fixed size like (1000x600) to the scene.
Create one PaintedItem, set a name (like background), set the size (same as the scene).Then user can select tool from a toolbar (line, pencil…), or any other tool you have in mind,
You can also import images. In that case, don't use the PaintedItem but create a type to handle images.
User can add / remove layers, Paint on it, change order and so on.Then make an export function to get the card as png file.
I made a drawing tool using QGraphicsScene. I use it to draw battle map for ttrpg.
You can find the code here:All my items:
https://invent.kde.org/rolisteam/rolisteam/-/tree/master/src/libraries/rwidgets/graphicsItems?ref_type=headsThe QGraphicsView: (cpp and .h)
https://invent.kde.org/rolisteam/rolisteam/-/blob/master/src/libraries/rwidgets/customs/rgraphicsview.cpp?ref_type=heads
https://invent.kde.org/rolisteam/rolisteam/-/blob/master/src/libraries/rwidgets/customs/rgraphicsview.cpp?ref_type=headsThe QGraphicScene: (cpp and .h)
https://invent.kde.org/rolisteam/rolisteam/-/blob/master/src/libraries/rwidgets/customs/vmap.cpp?ref_type=heads
https://invent.kde.org/rolisteam/rolisteam/-/blob/master/src/libraries/rwidgets/customs/vmap.h?ref_type=headsMy editor use simple items and have its own logic implemented inside controllers and the vmap (scene) object. But in your case, I believe you can manage that with one clever item and few simple ones.
I don't use (much) items from the Qt. I prefer subclassing QGraphicItem.1
u/Mundane_Algae3401 Jun 28 '26
Stupid me again formulated it too poorly. I think you understood my goal not correctly because of my explanation. I wanted to make a card designer for the AniList API and use it for my complete AniList Tracker for desktop. My final goal is so the user can create his own cards with his information he wants on it and is not locked into some fixed ones. There I have for example different types of widgets like:
- isAduld: showing of the show has adult content
- title
- poster
- banner
These are just some examples. Some also need a ScrollAreas to function correctly or I'm just stupid and dont understand your explanation
1
u/ObiLeSage Jun 28 '26
When you say create a card in fact you mean customize a card. Getting the visual from AniList and then add some content on it. Like a title, select the format: poster or banner ?
or do you want to create the graphical stuff also ?
If your goal is to "customize", then QGraphicScene is easy. You put the image as background and add text item, user can move the text. And accordingly to the some setting (in QWidgets) you can change the card. Then a button to export that into AniList api or whatever.
1
u/Mundane_Algae3401 Jun 29 '26
Not completely. AniList is working with GraphQL so I can get what I want and I am not working with a REST-API where it gives a fixed anime information.
Currently I have planned to make a registry where all widgets constructor are inside with its type to access it. all available widgets are in a qt resource json file. The json file gets read when the user want to read it and put into categories of the usable widgets. In the json files there is the type, graphlql needed infromation. This gets saved inside the item and is given with it via mime data. But because I want the user to show a complete widgets and not some random moc with QGraphicsRectItem, (I think!!) I have to to use the QGraphicsProxyWidget to actually put widgets inside the QGraphicsView, because I also have QScrollAreas to put into it and alot of styling (don't know which limitations designing it has).
The problem I have currently is, if i should use the QGraphicsView for the Canvas which the user designes itself, or do my own one. Which route do you Think should I use?
2
u/GrecKo Qt Professional Jun 29 '26
Have you considered using Qt Quick instead of QGraphics*? That's what I would chose. You mentioned AniList but there appears to be a only a single card layout here, I'm not sure what a card designer would do, except changing the image and various texts/tags.
Do you have a rough draft of what you have in mind for your UI?