I work with qtcreator to make qt apps.
I want to add mouseReleaseEvent to graphicsView created already with designer.
Here is my subclass
Q_OBJECT
public:
protected:
private slots:
private:
};
class MyView : public QGraphicsView {
Q_OBJECT
public:
MyView(QGraphicsView *graphicsView_skel, QWidget *parent = 0);
protected:
void mouseReleaseEvent(QMouseEvent *event);
private slots:
private:
QGraphicsScene *scene;
};
To copy to clipboard, switch view to plain text mode
Here is the code for creating scene on view and adding items
{
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);
}
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);
}
To copy to clipboard, switch view to plain text mode
I call it from
MainWindow
::MainWindow(QWidget *parent
)
{
ui->setupUi(this);
MyView(ui->graphicsView_skel);
}
MainWindow::MainWindow(QWidget *parent)
: QMainWindow(parent), ui(new Ui::MainWindowClass)
{
ui->setupUi(this);
MyView(ui->graphicsView_skel);
}
To copy to clipboard, switch view to plain text mode
Everything is ok but mouse relase event doesnt work
{
printf("Mouse released\n");
}
void MyView::mouseReleaseEvent(QMouseEvent *event)
{
printf("Mouse released\n");
QGraphicsView::mouseReleaseEvent(event);
}
To copy to clipboard, switch view to plain text mode
Can anyone help me?
Bookmarks