QGraphicsView vs custom QWidget



  • Hi,

    I wish to develop a custom widget. I am confused between using a custom QWidget handing the QPaintEvent, that draws on the window and a QGraphicsView+QGraphicsScene based implementation.

    In which scenario QPaintEvent based implementation makes sense?

    In which scenario QGraphicsScene based implementation makes sense?

    My application area is desktop. The custom widget I wish to develop is a grid of 1000's of rectangles, where I can click individual rectangles.

    Thanks,
    Lloyd


  • Moderators

    Both technics are eligible for the most use cases and have advantages and disadvantages.
    Since you have a high number of rects i would go with the QGraphicsView approach. It's very performant handling alot of items.
    Creating 1000's of QWidgets will be very memory intensive. And if you just create 1 widgets and paint 1000's of rects and handling the events accordingly determining the correct rect may be a pain.

    So i would prefer the way with the capsulation of lightweight QGraphicsItems in a QGraphicsView for every rect.



  • Thanks raven-worx for your response. Is there any way for me to get a specific answer for these questions?

    In which scenario QPaintEvent based implementation makes sense?

    In which scenario QGraphicsScene based implementation makes sense?

    or a comparison of these methods available someware in the documentation


  • Moderators

    i would say there is no specific answer to this question. It will always depend on your requirements/scenario.
    If you have many items and don't bother with the capsulation in a QGraphicsView go with it.
    If you depend on QWidget's features and/or need to pass them around in your application maybe this is approach is better.

    There is no strict answer available. Both have their right of existence. Experience will tell you when you work with both a bit after some times. As i said you may be able to achieve what you want with both technics... It really depends on what you want to achieve and how other aspects are important for you.

    Maybe you have time to implement both approaches and see which is more convenient for you.


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.