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. QGraphicsItem::type() enum value to key
Qt 6.11 is out! See what's new in the release blog

QGraphicsItem::type() enum value to key

Scheduled Pinned Locked Moved Unsolved General and Desktop
3 Posts 3 Posters 443 Views 2 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.
  • sonichyS Offline
    sonichyS Offline
    sonichy
    wrote on last edited by
    #1
    QList<QGraphicsItem*> list_GI = scene->selectedItems();
    for (int i=0; i<list_GI.size(); i++) {
        QMetaEnum metaEnum = QMetaEnum::fromType<QGraphicsItem::anonymous>(); //no member named 'anonymous' in 'QGraphicsItem';
        qDebug() << list_GI[i] << metaEnum.valueToKey(list_GI[i]->type());
        //qDebug() << list_GI[i] << list_GI[i]->type();
        //QGraphicsItem(0x7b6f60, pos=-53,-31, flags=(ItemIsMovable|ItemIsSelectable)) 10
    }
    

    For example: change qDebug 2 to QGraphicsPathItem.

    https://github.com/sonichy

    raven-worxR Pl45m4P 2 Replies Last reply
    0
    • sonichyS sonichy
      QList<QGraphicsItem*> list_GI = scene->selectedItems();
      for (int i=0; i<list_GI.size(); i++) {
          QMetaEnum metaEnum = QMetaEnum::fromType<QGraphicsItem::anonymous>(); //no member named 'anonymous' in 'QGraphicsItem';
          qDebug() << list_GI[i] << metaEnum.valueToKey(list_GI[i]->type());
          //qDebug() << list_GI[i] << list_GI[i]->type();
          //QGraphicsItem(0x7b6f60, pos=-53,-31, flags=(ItemIsMovable|ItemIsSelectable)) 10
      }
      

      For example: change qDebug 2 to QGraphicsPathItem.

      raven-worxR Offline
      raven-worxR Offline
      raven-worx
      Moderators
      wrote on last edited by
      #2

      @sonichy
      and your question is?

      --- 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
      1
      • sonichyS sonichy
        QList<QGraphicsItem*> list_GI = scene->selectedItems();
        for (int i=0; i<list_GI.size(); i++) {
            QMetaEnum metaEnum = QMetaEnum::fromType<QGraphicsItem::anonymous>(); //no member named 'anonymous' in 'QGraphicsItem';
            qDebug() << list_GI[i] << metaEnum.valueToKey(list_GI[i]->type());
            //qDebug() << list_GI[i] << list_GI[i]->type();
            //QGraphicsItem(0x7b6f60, pos=-53,-31, flags=(ItemIsMovable|ItemIsSelectable)) 10
        }
        

        For example: change qDebug 2 to QGraphicsPathItem.

        Pl45m4P Offline
        Pl45m4P Offline
        Pl45m4
        wrote on last edited by Pl45m4
        #3

        @sonichy

        You want that your qDebug prints QGraphicPathItem instead of type 10?

        See

        • https://doc.qt.io/qt-5/qgraphicsitem.html#type
        • https://doc.qt.io/qt-5/qgraphicsitem.html#anonymous-enum

        I guess the problem is, that the enum is not declared as Q_ENUM

        Qt source code:

        • https://code.woboq.org/qt5/qtbase/src/widgets/graphicsview/qgraphicsitem.h.html#QGraphicsPathItem::Type

        So QMetaEnum::fromType(......) wont work and you cant map the type integer to the name directly with fromType

        EDIT:

        I'm wondering why? :)
        Intentionally?

        Does anyone know more about this? Some public Qt enums are declared with Q_ENUM and some just don't...
        Qt::GlobalColor for example works fine and can get mapped perfectly.


        If debugging is the process of removing software bugs, then programming must be the process of putting them in.

        ~E. W. Dijkstra

        1 Reply Last reply
        1

        • Login

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