PDA

View Full Version : Adding events to GraphicsView created with designer



mkarakaplan
3rd May 2009, 21:36
I work with qtcreator to make qt apps.
I want to add mouseReleaseEvent to graphicsView created already with designer.

Here is my subclass


class MyView : public QGraphicsView {
Q_OBJECT
public:
MyView(QGraphicsView *graphicsView_skel, QWidget *parent = 0);
protected:
void mouseReleaseEvent(QMouseEvent *event);
private slots:
private:
QGraphicsScene *scene;
};

Here is the code for creating scene on view and adding items


MyView::MyView(QGraphicsView *view_skel,QWidget *parent) : QGraphicsView(parent)

{
scene = new QGraphicsScene(view_skel);
scene->setSceneRect(0, 0, 250, 500);
view_skel->setScene(scene);
ImageItem *image;
image = new ImageItem(1, QPixmap("icons/skel2.png"));
image->setData(0, 0);
image->setPos(30, 100);
scene->addItem(image);
}

I call it from

MainWindow::MainWindow(QWidget *parent)
: QMainWindow(parent), ui(new Ui::MainWindowClass)

{
ui->setupUi(this);
MyView(ui->graphicsView_skel);
}

Everything is ok but mouse relase event doesnt work


void MyView::mouseReleaseEvent(QMouseEvent *event)
{
printf("Mouse released\n");
QGraphicsView::mouseReleaseEvent(event);
}


Can anyone help me?

wagmare
4th May 2009, 06:32
replace the virtual function ..
QGraphicsView:mouseReleaseEvent(QMouseEvent *event)
with ....
QGraphicsView ::mouseReleaseEvent(QGraphicsSceneMouseEvent *event)

mkarakaplan
4th May 2009, 11:57
replace the virtual function ..
QGraphicsView:mouseReleaseEvent(QMouseEvent *event)
with ....
QGraphicsView ::mouseReleaseEvent(QGraphicsSceneMouseEvent *event)

Didnt worked. I am writing all project again without qtdesigner.
Thanks.