Qt 6.11 is out! See what's new in the release
blog
QGraphicsItem::type() enum value to key
-
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.
-
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.
@sonichy
and your question is? -
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.
You want that your
qDebugprintsQGraphicPathIteminstead of type10?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_ENUMQt source code:
So
QMetaEnum::fromType(......)wont work and you cant map thetypeinteger to the name directly withfromTypeEDIT:
I'm wondering why? :)
Intentionally?Does anyone know more about this? Some public Qt enums are declared with
Q_ENUMand some just don't...
Qt::GlobalColorfor example works fine and can get mapped perfectly.