Results 1 to 18 of 18

Thread: Question about drag and drop in QGraphicsView

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #5
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,368
    Thanks
    3
    Thanked 5,018 Times in 4,794 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Question about drag and drop in QGraphicsView

    Your code has a lot of problems such as this:
    Qt Code:
    1. void MainWindow::paintEvent(QPaintEvent*)
    2. {
    3. QPainter painter(this);
    4. QPen pen(Qt::gray, 3, Qt::SolidLine, Qt::RoundCap, Qt::RoundJoin);
    5. painter.setPen(pen);
    6. ui->graphicsView->setScene(m_scene);
    7. }
    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).
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  2. The following user says thank you to wysota for this useful post:

    meazza (30th March 2011)

Similar Threads

  1. Drag from QtreeWidget and drop to QGraphicsView
    By syjgin in forum Qt Programming
    Replies: 0
    Last Post: 3rd July 2010, 14:17
  2. Drag and Drop from QListWidget to QGraphicsView (Scene)
    By fritzone in forum Qt Programming
    Replies: 0
    Last Post: 16th June 2010, 09:41
  3. How to drag and drop on QGraphicsView frame
    By wudelei in forum Qt Programming
    Replies: 1
    Last Post: 16th April 2010, 08:04
  4. Drag and Drop from QListView to QGraphicsView
    By NoRulez in forum Qt Programming
    Replies: 0
    Last Post: 20th August 2009, 14:26
  5. Drag and drop from QTreeWidget to QGraphicsView
    By igu@na in forum Qt Programming
    Replies: 2
    Last Post: 27th August 2008, 08:24

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Qt is a trademark of The Qt Company.