Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. QGraphicsView vs custom QWidget
Forum Updated to NodeBB v4.3 + New Features

QGraphicsView vs custom QWidget

Scheduled Pinned Locked Moved General and Desktop
4 Posts 2 Posters 3.5k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • L Offline
    L Offline
    lloydqt
    wrote on last edited by
    #1

    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

    1 Reply Last reply
    0
    • raven-worxR Offline
      raven-worxR Offline
      raven-worx
      Moderators
      wrote on last edited by
      #2

      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.

      --- SUPPORT REQUESTS VIA CHAT WILL BE IGNORED ---
      If you have a question please use the forum so others can benefit from the solution in the future

      1 Reply Last reply
      0
      • L Offline
        L Offline
        lloydqt
        wrote on last edited by
        #3

        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

        1 Reply Last reply
        0
        • raven-worxR Offline
          raven-worxR Offline
          raven-worx
          Moderators
          wrote on last edited by
          #4

          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.

          --- SUPPORT REQUESTS VIA CHAT WILL BE IGNORED ---
          If you have a question please use the forum so others can benefit from the solution in the future

          1 Reply Last reply
          0

          • Login

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • Users
          • Groups
          • Search
          • Get Qt Extensions
          • Unsolved