Important: Please read the Qt Code of Conduct -

Building UI with QGraphics

  • Hi

    I'm trying to learn how to build custom ui's with the QGraphics classes. However there are a lot of those and I'm having trouble finding out where to start, and which of them I should be using.

    For testing out the various features I have chosen to make sort of a media center ui for browsing music albums and tracks. This should consist of 2 "pages".

    Page 1: "":
    Page 2: "":

    The first page would show album covers and a title, and the user should be able to scroll through these. When an album is picked, some transition should lead the user to the next page.

    How should I go about doing this? Should the pages be 2 GraphicsViews or GraphicsScenes or something completely different? Should the individual elements on the pages be grouped in GraphicsLayouts or GraphicsItemGroups?

    Thanks in advance.

  • There are different ways to use graphics views, where I prefer using paged layouts where all pages are kept in memory, this wastes memory unnecessarily, so using single graphics view which gets every time you switch to different ”page” data parsed from source, for example using your own scene.

  • Have you considered using QML instead of QGraphics (if possible)?

  • Note that these days, you have quite a few options for creating custom UI screens in Qt:

    • Custom widgets with their own custom painting

    • Using stylesheets

    • Developing a custom QStyle

    • Using QGraphicsView

    • Using QML

    A lot of developers use QGraphicsView, because it's hot and new and cool (can something be both hot and cool?), but often what they do is not really what QGraphicsView was made for (which is many small independent objects, possibly moving, possibly animated). What you are trying to do could just as well be done using existing widgets and a custom style (and depending on the complexity beyond what you show in the screenshots, maybe even with stylesheets).

    Of course, if what you are really after is learning about QGV, then by all means go ahead and have fun, and in that case, I agree with Smar for relatively static scenes.

  • if u want to explore other widgets, u culd just use the QTabWidget.. with 2 tabs, 2nd tab gets the focus when you pick the album in the first

  • Thanks for all of your answers, much appreciated. I've tried to look at qml and it seems like it can accomplish what I want, and it is relatively simple as well.

Log in to reply