Your code has a lot of problems such as this:
{
QPen pen
(Qt
::gray,
3, Qt
::SolidLine, Qt
::RoundCap, Qt
::RoundJoin);
painter.setPen(pen);
ui->graphicsView->setScene(m_scene);
}
void MainWindow::paintEvent(QPaintEvent*)
{
QPainter painter(this);
QPen pen(Qt::gray, 3, Qt::SolidLine, Qt::RoundCap, Qt::RoundJoin);
painter.setPen(pen);
ui->graphicsView->setScene(m_scene);
}
To copy to clipboard, switch view to plain text mode
Adding items in mouse move events is probably a bad idea as well. Spaghetti code doesn't help too, try simplifying it.
As for your problem - if you want to make items movable, you don't need to use drag and drop, that's for something else. You can make items movable by setting the ItemIsMovable flag on the item and making sure the scene has a chance to process mouse events (that is if you reimplement mouse event handlers, be sure to call the base class implementation).
Bookmarks