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. If override QGraphicsView::resizeEvent, should I call the base function as well?

If override QGraphicsView::resizeEvent, should I call the base function as well?

Scheduled Pinned Locked Moved Unsolved General and Desktop
4 Posts 2 Posters 717 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.
  • S Offline
    S Offline
    Snorkelbuckle
    wrote on last edited by
    #1

    I have derived class that inherits from QGraphicsView, I have need to override QGraphicsView::resizeEvent(QResizeEvent*), I am just changing the properties of some elements when the QGraphicsView size changes. I noticed that QGraphicsView itself apparently re-declares resizeEvent as well (according to the refactoring feature of Qt Creator). My question is simple, should I also call the base QGraphicsView::resizeEvent as well, or does it magically do it's resizeEvent thing regardless if I have made override function? If I should call the base function as well, should I do it before or after I do my custom stuff?

    Thanks.

    1 Reply Last reply
    0
    • Christian EhrlicherC Offline
      Christian EhrlicherC Offline
      Christian Ehrlicher
      Lifetime Qt Champion
      wrote on last edited by Christian Ehrlicher
      #2

      @snorkelbuckle said in If override QGraphicsView::resizeEvent, should I call the base function as well?:

      or does it magically do it's resizeEvent thing regardless if I have made override function?

      How should this work when you don't call the base function? C++ Basics.
      See for example here: https://www.programiz.com/cpp-programming/multilevel-multiple-inheritance

      Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
      Visit the Qt Academy at https://academy.qt.io/catalog

      1 Reply Last reply
      3
      • S Offline
        S Offline
        Snorkelbuckle
        wrote on last edited by
        #3

        Thanks for that, but I'm not clear on what you are asking. I do know the basics, thank you. I guess I should be more clear, I'm asking what exactly does the re implemented base function of resizeEvent in QGraphicsView actually do? I need to know this to determine if I should call the re implemented base function in my override function. Technically it is not required to call the base function unless there is something important it needs to do that is documented. And therein lies the root of the problem, there is no documentation about what the re-implementation does in QGraphicsView. All that is documented is that it is "re implemented". So there needs to be an explanation to the developer in case developer re-implements in his derived class which I have done.

        As to your question, I don't know how it should work, that is why I'm asking, will QGraphicsView work correctly if I call the base function or should I not call the base function, and if I call the base function, in what order should I call it.

        1 Reply Last reply
        0
        • Christian EhrlicherC Offline
          Christian EhrlicherC Offline
          Christian Ehrlicher
          Lifetime Qt Champion
          wrote on last edited by
          #4

          You really should call the Qt base class implementations in all cases - https://code.woboq.org/qt5/qtbase/src/widgets/graphicsview/qgraphicsview.cpp.html#_ZN13QGraphicsView11resizeEventEP12QResizeEvent

          Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
          Visit the Qt Academy at https://academy.qt.io/catalog

          1 Reply Last reply
          2

          • Login

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