Hi all,
I have a problem which need help.
I have a graphicsview which contains a graphicsscene. I want to do something on a mouse click on the graphicsview object.
How can I do this?
mainwindow .h
private:
private:
QGraphicsEllipseItem *item;
QGraphicsView *view;
QGraphicsScene *scene;
To copy to clipboard, switch view to plain text mode
mainwindow.cpp
MainWindow
::MainWindow(QWidget *parent
){
item->setRect(50, 100, 5, 5); //for setting position and size
item->setBrush(Qt::red);
scene->setSceneRect(0, 0, 600, 600);
scene->addItem(item);
view
->setBackgroundBrush
(QPixmap(":/image/map.jpg"));
...
}
MainWindow::MainWindow(QWidget *parent)
: QMainWindow(parent)
{
item = new QGraphicsEllipseItem;
item->setRect(50, 100, 5, 5); //for setting position and size
item->setBrush(Qt::red);
scene = new QGraphicsScene;
scene->setSceneRect(0, 0, 600, 600);
scene->addItem(item);
view = new QGraphicsView(scene);
view->setDragMode(QGraphicsView::ScrollHandDrag);
view->setBackgroundBrush(QPixmap(":/image/map.jpg"));
...
}
To copy to clipboard, switch view to plain text mode
Bookmarks