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. Getting the parent from QGraphicsScene?

Getting the parent from QGraphicsScene?

Scheduled Pinned Locked Moved Unsolved General and Desktop
7 Posts 4 Posters 812 Views
  • 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.
  • Clone45C Offline
    Clone45C Offline
    Clone45
    wrote on last edited by Clone45
    #1

    Hello!

    I've googled for this, read the docs, and asked ChatGPT, so I think there might not be a direct way. However, I'll ask just in case: Is there a way that I can get the "parent" that's passed in to a QGraphicsScene?

    I was just considering inheriting from QGraphicsScene to store the parent when I realized that it already takes a parent as an optional constructor. If I could access that, I won't need to create an additional class.

    Thanks!

    C JonBJ 2 Replies Last reply
    0
    • Clone45C Clone45

      Hello!

      I've googled for this, read the docs, and asked ChatGPT, so I think there might not be a direct way. However, I'll ask just in case: Is there a way that I can get the "parent" that's passed in to a QGraphicsScene?

      I was just considering inheriting from QGraphicsScene to store the parent when I realized that it already takes a parent as an optional constructor. If I could access that, I won't need to create an additional class.

      Thanks!

      C Offline
      C Offline
      ChrisW67
      wrote on last edited by
      #2

      @Clone45 QGraphicsScene is a QObject, so just call QObject::parent()... or have I missed something.

      W 1 Reply Last reply
      2
      • C ChrisW67

        @Clone45 QGraphicsScene is a QObject, so just call QObject::parent()... or have I missed something.

        W Offline
        W Offline
        wrosecrans
        wrote on last edited by
        #3

        Yup, like Chris said, just call parent().

        In general, the documentation is way more useful than a chatbot: https://doc.qt.io/qt-6/qgraphicsscene-members.html#:~:text=parent() const %3A QObject *

        1 Reply Last reply
        1
        • Clone45C Clone45

          Hello!

          I've googled for this, read the docs, and asked ChatGPT, so I think there might not be a direct way. However, I'll ask just in case: Is there a way that I can get the "parent" that's passed in to a QGraphicsScene?

          I was just considering inheriting from QGraphicsScene to store the parent when I realized that it already takes a parent as an optional constructor. If I could access that, I won't need to create an additional class.

          Thanks!

          JonBJ Offline
          JonBJ Offline
          JonB
          wrote on last edited by
          #4

          @Clone45
          As both above have said. It's a QObject, which optionally takes a QObject *parent constructor argument which can be accessed via parent() method thereafter.

          However, just as a tip, why do you want/need to access this parent? It's even optional, so could be null. There are always reasons/exceptions, but by and large QObjects really should not know about or need to access their parent. Only parents access children. Food for thought.

          Clone45C 1 Reply Last reply
          0
          • JonBJ JonB

            @Clone45
            As both above have said. It's a QObject, which optionally takes a QObject *parent constructor argument which can be accessed via parent() method thereafter.

            However, just as a tip, why do you want/need to access this parent? It's even optional, so could be null. There are always reasons/exceptions, but by and large QObjects really should not know about or need to access their parent. Only parents access children. Food for thought.

            Clone45C Offline
            Clone45C Offline
            Clone45
            wrote on last edited by
            #5

            @JonB said in Getting the parent from QGraphicsScene?:

            However, just as a tip, why do you want/need to access this parent? It's even optional, so could be null. There are always reasons/exceptions, but by and large QObjects really should not know about or need to access their parent. Only parents access children. Food for thought.

            Thanks for the insight. I'll keep that in mind. It would take a while to explain what I'm doing, and unfortunately I have to run off to work, but if I post again about this, I'll follow up with additional details. Thanks!!

            JonBJ 1 Reply Last reply
            0
            • Clone45C Clone45

              @JonB said in Getting the parent from QGraphicsScene?:

              However, just as a tip, why do you want/need to access this parent? It's even optional, so could be null. There are always reasons/exceptions, but by and large QObjects really should not know about or need to access their parent. Only parents access children. Food for thought.

              Thanks for the insight. I'll keep that in mind. It would take a while to explain what I'm doing, and unfortunately I have to run off to work, but if I post again about this, I'll follow up with additional details. Thanks!!

              JonBJ Offline
              JonBJ Offline
              JonB
              wrote on last edited by
              #6

              @Clone45
              You can always subclass QGraphicsScene to add your own explicit pointer to some specialized class with relevant stuff in it. Just it would be best if it does not rely on its QObjects parent's characteristics too much.

              Clone45C 1 Reply Last reply
              0
              • JonBJ JonB

                @Clone45
                You can always subclass QGraphicsScene to add your own explicit pointer to some specialized class with relevant stuff in it. Just it would be best if it does not rely on its QObjects parent's characteristics too much.

                Clone45C Offline
                Clone45C Offline
                Clone45
                wrote on last edited by
                #7

                @JonB said in Getting the parent from QGraphicsScene?:

                @Clone45
                You can always subclass QGraphicsScene to add your own explicit pointer to some specialized class with relevant stuff in it. Just it would be best if it does not rely on its QObjects parent's characteristics too much.

                Thank you. I think that I'm leaning that the hard way tonight. I'll go ahead and subclass QGraphicsScene and manage the relationship myself.

                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