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. Food for thought: Why isn't QGraphicsView::setScene a virtual function?
Forum Updated to NodeBB v4.3 + New Features

Food for thought: Why isn't QGraphicsView::setScene a virtual function?

Scheduled Pinned Locked Moved General and Desktop
6 Posts 5 Posters 2.8k 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.
  • C Offline
    C Offline
    ccjmoey
    wrote on last edited by
    #1

    Hi.

    I am wondering whether anyone is able to see why QGraphicsView::setScene would be better off being a virtual function?

    I think when it is a virtual function, whenever you create a derived class from QGraphicsView, you can override the function and re-implement new functionality to include some custom connections and others. It also allows the new class to fully encapsulate what it needs to do rather than assigning the scene to it and make connections call outside the class.

    If it is a good suggestion, how do I suggest this enhancement to Qt developers?

    Thanks. :)

    1 Reply Last reply
    0
    • F Offline
      F Offline
      Franzk
      wrote on last edited by
      #2

      Your idea is essentially not a bad idea. There are however two things to consider that may shed light on why this is not the chosen implementation (note that I'm reasoning about the choice, I haven't made it). The first is that if you allow setScene() to be overridden, your base class may not work as expected to the outside world; the set functionality could be denied by the overload: @void MyOverload::setScene(QGraphicsScene )
      {
      /
      neener neener neener! Up yours, QGraphicsView! */
      }@

      The second is that QGraphicsView is a view class and it tells the scene about all the events it receives. There really is no need to overload QGraphicsView. Almost in all cases it is a better choice to have a widget that contains the graphics view and add any functionality that you don't implement in the scene in the container widget.

      "Horse sense is the thing a horse has which keeps it from betting on people." -- W.C. Fields

      http://www.catb.org/~esr/faqs/smart-questions.html

      1 Reply Last reply
      0
      • D Offline
        D Offline
        dangelog
        wrote on last edited by
        #3

        [quote author="Jason X" date="1303308416"]Hi.

        I am wondering whether anyone is able to see why QGraphicsView::setScene would be better off being a virtual function?

        I think when it is a virtual function, whenever you create a derived class from QGraphicsView, you can override the function and re-implement new functionality to include some custom connections and others. It also allows the new class to fully encapsulate what it needs to do rather than assigning the scene to it and make connections call outside the class.

        If it is a good suggestion, how do I suggest this enhancement to Qt developers?

        Thanks. :)[/quote]

        Can you make a detailed example of such functionality? (BTW, note that adding new virtuals is forbidden during Qt 4 lifetime. It would mean going for "implementation slots".)

        Software Engineer
        KDAB (UK) Ltd., a KDAB Group company

        1 Reply Last reply
        0
        • K Offline
          K Offline
          Keith Cancel
          wrote on last edited by
          #4

          It is an open source library and if you really feel it is necessary for what your trying to do you could make a modified version of the class with setscene as a virtual function. Then you could inherent from your modified version and re-implement setscene to your needs. That is one nice thing about an open-source library is you can modify the library itself and add to it.

          ♫♪♪^。^ Always Whistling A Tune!

          1 Reply Last reply
          0
          • F Offline
            F Offline
            Franzk
            wrote on last edited by
            #5

            [quote author="Keith Cancel" date="1303343176"]It is an open source library and if you really feel it is necessary for what your trying to do you could make a modified version of the class with setscene as a virtual function. Then you could inherent from your modified version and re-implement setscene to your needs. That is one nice thing about an open-source library is you can modify the library itself and add to it. [/quote]

            Nice as it may be, you still have to consider the fact that you are going to have to maintain the patch. It would really be a waste of time to do that if the desired functionality doesn't really need to be in the graphics view in the first place ;-) .

            "Horse sense is the thing a horse has which keeps it from betting on people." -- W.C. Fields

            http://www.catb.org/~esr/faqs/smart-questions.html

            1 Reply Last reply
            0
            • A Offline
              A Offline
              andre
              wrote on last edited by
              #6

              I agree with Franzk: what would introducing this bring in terms of benefits that encapsulating a QGraphicsView does not?

              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