PDA

View Full Version : not drag and drop on a QGraphicsTextItem



jano_alex_es
16th October 2009, 15:01
Hi, I'm trying to solve a problem I was postponing during too much time and now I'm out of ideas.

I have a subclassed QGraphicsTextItem that only receives the drag and drop event when "mousePressEvent" is not implemented. Everything, everything works perfectly (edit text, change the font...) but drag&drop.



#pragma once
#ifndef ITEXTOITEM_H
#define ITEXTOITEM_H

#include "Common/TextoItem.h"
#include <QMenu>

class CITextoItem : public CTextoItem //CTextoItem inherits from QGraphicsTextItem
{
Q_OBJECT

public:
CITextoItem();
~CITextoItem();

private:
void mousePressEvent(QGraphicsSceneMouseEvent *event);

QMenu* m_pMenu;

private slots:
void menuClicked(QAction* pAction);
};

#endif //ITEXTOITEM




void CITextoItem::mousePressEvent(QGraphicsSceneMouseEv ent *event)
{//it should work...
QGraphicsItem::mousePressEvent(event);
}




just in case, the father's class

#pragma once
#ifndef TEXTOITEM_H
#define TEXTOITEM_H

#include "FormElemItem.h"
#include <QGraphicsTextItem>
#include <QObject>

class CTextoItem : public QGraphicsTextItem
{
Q_OBJECT

public:
enum { Type = UserType + 5 };
int type() const
{
// Enable the use of qgraphicsitem_cast with this item.
return Type;
}

CTextoItem();
~CTextoItem();
};

#endif //TEXTOITEM_H

It doesn't mind the code I have inside the mousePressEvent function, drag&drop doesn't work if the function is implemented and it works perfectly if I remove it.

Do you have any clue? right now, I'm out of ideas.

thanks!

high_flyer
16th October 2009, 15:50
mousePressEvent() should be public

jano_alex_es
19th October 2009, 09:09
it does not work either...

Should be always public? visual-studio/Qt implements it as private by default. By the way, I can edit the text and it receives events, everything ok but drag&dropping.

Lykurg
19th October 2009, 09:32
Try to make it protected (that's what I use allways...) and
void CITextoItem::mousePressEvent(QGraphicsSceneMouseEv ent *event)
{
QGraphicsTextItem::mousePressEvent(event);
// or if that don't work
// CTextoItem::mousePressEvent(event);
}

jano_alex_es
19th October 2009, 09:49
thanks! calling the function from the child, works...

Now I'm checking the Qt code and yes, some graphics item have a different implementations of those supposed inherited members :S In my opinion, and it's just my opinion, this is a terrible mistake in the Qt Assistant, because I assume "QGraphicsTextItem" calls directly its parent's function.