Results 1 to 18 of 18

Thread: Question about drag and drop in QGraphicsView

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Mar 2011
    Posts
    63
    Thanks
    11
    Thanked 5 Times in 5 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Question about drag and drop in QGraphicsView

    I have to click on the edge of the item, and it has to be on the pixel. Very hard to click it with the mouse.

  2. #2
    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

    Apparently the inside of the item is empty. If simply setting a brush doesn't help you'll have to reimplement the shape() of the item.
    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.


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

    meazza (31st March 2011)

  4. #3
    Join Date
    Mar 2011
    Posts
    63
    Thanks
    11
    Thanked 5 Times in 5 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Question about drag and drop in QGraphicsView

    I fixed it i think. I thought since i add the items during a pressEvent and when i tried to move the item i press the mouse so the pressEvent funktion was called hence not allowing me to move it. So added QGraphicsScene::mousePressEvent(mouseEvent); if iwas not adding items in the pressEvent.

    Well it works now but do you find this a reasonable solution?

  5. #4
    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

    I don't think adding items in a mouse press event is a reasonable solution. I tend to lean towards more high-level solutions.
    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.


  6. #5
    Join Date
    Mar 2011
    Posts
    63
    Thanks
    11
    Thanked 5 Times in 5 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Question about drag and drop in QGraphicsView

    Well I am not a master of zen yet , but hopefully someday I will be. What would that high-level solution be? Just asking out of curiosity, not gonna try it out this time. Not high-level yet .

    Thanks for all your help

  7. #6
    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

    Like emitting a signal "hey, I want item to be added at these coordinates" and then handling it in a dedicated method that can be called from different contexts. And mousePress is probably a bad place to do it anyway, mouseRelease would be a better one.
    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.


  8. #7
    Join Date
    Sep 2010
    Location
    Tel Aviv, Israel
    Posts
    26
    Thanks
    2
    Qt products
    Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: Question about drag and drop in QGraphicsView

    What about the solution of reimplement the function mouseMoveEvent()?
    You can do something like that too:
    Qt Code:
    1. void Object::mouseMoveEvent(QMouseEvent *event){
    2. PolygonItem->move(event->x(),event->y());
    3. }
    To copy to clipboard, switch view to plain text mode 

  9. #8
    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

    Sure but why if you have the ItemIsMovable flag?
    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.


  10. #9
    Join Date
    Mar 2011
    Posts
    63
    Thanks
    11
    Thanked 5 Times in 5 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Question about drag and drop in QGraphicsView

    I have found another question. How do QWidgets behave in the graphicsscene? Do I need to use the QGraphicsProxyWidget to be able to move it or? Because i cant set flags to a normal QWidget.

    Qt Code:
    1. Embedded *MyWidget = new Embedded();
    2. QGraphicsProxyWidget *proxy = new QGraphicsProxyWidget();
    3. proxy = addWidget(MyWidget);
    4. proxy->setFlags(QGraphicsItem::ItemIsMovable | QGraphicsItem::ItemIsSelectable);
    5. proxy->setPos(mouseEvent->scenePos());
    6. addItem(proxy);
    7. figur = 0;
    To copy to clipboard, switch view to plain text mode 

    I tried this and it positions as i would like to but cant move it..Maybe I am waaaay out there on this one

  11. #10
    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

    I'd say you can't move it because the widget handles the event so it never reaches the scene code responsible for moving the item.
    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.


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.