Alles rund um die Programmierung mit Qt
toto12
Beiträge: 8 Registriert: 26. Dezember 2006 13:40
Beitrag
von toto12 » 31. Dezember 2006 01:26
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.
Zuletzt geändert von
toto12 am 4. Januar 2007 11:23, insgesamt 1-mal geändert.
toto12
Beiträge: 8 Registriert: 26. Dezember 2006 13:40
Beitrag
von toto12 » 31. Dezember 2006 10:42
Code: Alles auswählen
ucvTestItem = static_cast<UcvGraphicTextItem *>(item);
Dieser cast geht nun! Aber warum geht der qgraphicsitem_cast nicht?
toto12.
upsala
Beiträge: 3946 Registriert: 5. Februar 2006 20:52
Wohnort: Landshut
Kontaktdaten:
Beitrag
von upsala » 31. Dezember 2006 11:08
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.
toto12
Beiträge: 8 Registriert: 26. Dezember 2006 13:40
Beitrag
von toto12 » 31. Dezember 2006 12:37
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.