Seite 1 von 1

[Newbie][solved]: qgraphicsitem_cast funktioniert nicht

Verfasst: 31. Dezember 2006 01:26
von toto12
Hallo,

der qgraphicsitem_cast funktioniert bei mir nicht. Kompiler und Debugger melden keine Fehler.

UcvGraphicsView ist eine abgeleitete Klasse von QGraphicsView.
UcvGraphicTextItem ist eine abgeleitete Klasse von QGraphicTextItem.

Code: Alles auswählen

void UcvGraphicsView::mouseDoubleClickEvent ( QMouseEvent * event ) 
{
        QPointF pointScene = mapToScene(event->pos());

	UcvGraphicTextItem * ucvTestItem;
    if (QGraphicsItem * item = graphicsScene->itemAt(pointScene)) {
		ucvTestItem = qgraphicsitem_cast<UcvGraphicTextItem *>(item);
    }

	QGraphicsView::mouseDoubleClickEvent (event );
}
Ich bekomme immer NULL zurück.

Danke für einen Tipp.

toto12.

Verfasst: 31. Dezember 2006 10:42
von toto12

Code: Alles auswählen

 ucvTestItem = static_cast<UcvGraphicTextItem *>(item); 
Dieser cast geht nun! Aber warum geht der qgraphicsitem_cast nicht?

toto12.

Verfasst: 31. Dezember 2006 11:08
von upsala
Aus der Doku
The lowest permitted type value for custom items (subclasses of QGraphicsItem or any of the standard items). This value is used in conjunction with a reimplementation of QGraphicsItem::type() and declaring a Type enum value.

Verfasst: 31. Dezember 2006 12:37
von toto12
Genauso habe ich es implementiert:

Code: Alles auswählen

class UcvGraphicsScene : public QGraphicsScene
{
    Q_OBJECT

public:
    UcvGraphicsScene();
    
    enum { 	ChapterItem = QGraphicsItem::UserType + 1 ,
    		TextItem };
...

class UcvGraphicTextItem : public QGraphicsTextItem
{
    Q_OBJECT

public:
    UcvGraphicTextItem(int & id, const QString & text);
    int type() const {return UcvGraphicsScene::TextItem; };
...
Oder was mache ich falsch?

toto12.