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. Is there a list of QGraphicsItem types?
Qt 6.11 is out! See what's new in the release blog

Is there a list of QGraphicsItem types?

Scheduled Pinned Locked Moved Solved General and Desktop
12 Posts 3 Posters 1.3k 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.
  • idlefrogI Offline
    idlefrogI Offline
    idlefrog
    wrote on last edited by idlefrog
    #3

    @Christian-Ehrlicher I'm trying to identify all the objects in the scene, and avoid placing a context menu over certain items. Although perhaps I should know what's in my scene and I have this back to front. But there are many items small & big.

    JonBJ 1 Reply Last reply
    0
    • idlefrogI idlefrog

      @Christian-Ehrlicher I'm trying to identify all the objects in the scene, and avoid placing a context menu over certain items. Although perhaps I should know what's in my scene and I have this back to front. But there are many items small & big.

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

      @idlefrog
      If you use woboq to look at the source for QGraphicsItem::type() you'll come across e.g.

      class Q_WIDGETS_EXPORT QGraphicsEllipseItem
       enum { Type = 4 };
      int type() const override;
      int QGraphicsEllipseItem::type() const
      {
          return Type;
      }
      

      in various files. So it's done via an "anonymous enum", defined in each derived class. I can't see anything which gathers those all together for you.

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

        But why you can't simply compare the type() integer with the ones you want to be able to show a context menu and use e.g. QGraphicsEllipseItem::Type instead an integer?

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

        idlefrogI 1 Reply Last reply
        0
        • Christian EhrlicherC Christian Ehrlicher

          But why you can't simply compare the type() integer with the ones you want to be able to show a context menu and use e.g. QGraphicsEllipseItem::Type instead an integer?

          idlefrogI Offline
          idlefrogI Offline
          idlefrog
          wrote on last edited by idlefrog
          #6

          @Christian-Ehrlicher Well, I don't know what they are, or where they are made, and they don't have any object name. I'm trying to reverse engineer in a way. It seems as if I will have to add 'type()' methods to all the prime suspects, but it's not a systematic approach.

          Which makes me think that perhaps my approach is all wrong here.
          Anyhow, your help is much appreciated! Any suggestions are welcome :)

          Christian EhrlicherC 1 Reply Last reply
          0
          • JonBJ JonB

            @idlefrog
            If you use woboq to look at the source for QGraphicsItem::type() you'll come across e.g.

            class Q_WIDGETS_EXPORT QGraphicsEllipseItem
             enum { Type = 4 };
            int type() const override;
            int QGraphicsEllipseItem::type() const
            {
                return Type;
            }
            

            in various files. So it's done via an "anonymous enum", defined in each derived class. I can't see anything which gathers those all together for you.

            idlefrogI Offline
            idlefrogI Offline
            idlefrog
            wrote on last edited by
            #7

            @JonB Thanks! Although for now, I'll just make do with grepping the qgraphicsitem.h if need be. Am currently reviewing / inspecting the code to understand it, and perhaps find out who's who in my scene!

            1 Reply Last reply
            0
            • idlefrogI idlefrog

              @Christian-Ehrlicher Well, I don't know what they are, or where they are made, and they don't have any object name. I'm trying to reverse engineer in a way. It seems as if I will have to add 'type()' methods to all the prime suspects, but it's not a systematic approach.

              Which makes me think that perhaps my approach is all wrong here.
              Anyhow, your help is much appreciated! Any suggestions are welcome :)

              Christian EhrlicherC Offline
              Christian EhrlicherC Offline
              Christian Ehrlicher
              Lifetime Qt Champion
              wrote on last edited by
              #8

              @idlefrog said in Is there a list of QGraphicsItem types?:

              It seems as if I will have to add 'type()' methods to all the prime suspect

              You're aware that such a function already exists? Still don't understand the problem.

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

              idlefrogI 1 Reply Last reply
              0
              • Christian EhrlicherC Christian Ehrlicher

                @idlefrog said in Is there a list of QGraphicsItem types?:

                It seems as if I will have to add 'type()' methods to all the prime suspect

                You're aware that such a function already exists? Still don't understand the problem.

                idlefrogI Offline
                idlefrogI Offline
                idlefrog
                wrote on last edited by
                #9

                @Christian-Ehrlicher Sorry, I probably am not being that clear. But I have a number of derived classes from QGraphicsItem, but even with the debugger can't identify them. So if I add 'type()' methods to those, I should start to identify the classes that I'm clicking on, and were they are. But knowing their base type is of course a start.

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

                  If you want to distinguish between your custom types and use qgraphicsitem_cast<> you have to define unique id's returned by type().

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

                  idlefrogI 1 Reply Last reply
                  1
                  • Christian EhrlicherC Christian Ehrlicher

                    If you want to distinguish between your custom types and use qgraphicsitem_cast<> you have to define unique id's returned by type().

                    idlefrogI Offline
                    idlefrogI Offline
                    idlefrog
                    wrote on last edited by
                    #11

                    @Christian-Ehrlicher Thanks... am just starting to do that. Although I wondering how best to allocate the ID's without creating some god enum object. So I may just for settle on picking unique/random IDs for just those that I suspect are under the cursor.

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

                      Noone stops you from defining an enum by yourself starting with Qt::UserType.

                      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

                      • Login

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