Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. QGraphicsScene drag and drop
Forum Updated to NodeBB v4.3 + New Features

QGraphicsScene drag and drop

Scheduled Pinned Locked Moved General and Desktop
11 Posts 4 Posters 13.1k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • A Offline
    A Offline
    andre
    wrote on last edited by
    #2

    Reimplementing virtual methods is always tricky. I think your problem is, is that your Scene implementation doesn't call the base class implementation of the virtual methods you reimplemented. This way, you disabled Qt's own event propagation mechanisms that are implemented in the base classes.

    Unless you're sure you should not, always call the base class implementation in your reimplementation of a virtual class. It may do actual work you were not aware of.

    1 Reply Last reply
    0
    • O Offline
      O Offline
      Olorin5800
      wrote on last edited by
      #3

      Thanks for the answer I thought that to.


      My programs never have bugs, they just develop random features.

      1 Reply Last reply
      0
      • G Offline
        G Offline
        goetz
        wrote on last edited by
        #4

        What is the error on //here?
        Is the method called at all?
        Is it called but you do not get into accepting the event?

        http://www.catb.org/~esr/faqs/smart-questions.html

        1 Reply Last reply
        0
        • A Offline
          A Offline
          andre
          wrote on last edited by
          #5

          [quote author="Olorin5800" date="1294919561"]Thanks for the answer I thought that to.[/quote]
          But...? That doesn't solve your issue?

          1 Reply Last reply
          0
          • O Offline
            O Offline
            Olorin5800
            wrote on last edited by
            #6

            [quote author="Andre" date="1294921290"]
            [quote author="Olorin5800" date="1294919561"]Thanks for the answer I thought that to.[/quote]
            But...? That doesn't solve your issue?

            [/quote]

            Can't test right now but looking through the qt source code not calling the base implementation seems to be the problem in the qgraphicsscene implementation of the drag move event is where the forwarding is taking place my code overrides the event and never calls the parent.

            [quote author="Volker" date="1294920632"]What is the error on //here?
            Is the method called at all?
            Is it called but you do not get into accepting the event?[/quote]

            No error the method where t i put the comment is not called in the item class if overriding the scene implementation of drag enter, drag move and drop events.


            My programs never have bugs, they just develop random features.

            1 Reply Last reply
            0
            • G Offline
              G Offline
              goetz
              wrote on last edited by
              #7

              gnarf ... of course it does not call the dragEnterEvent method of your item if the scene already accepts the drag!

              If you eventually drop your drag - there is only one object to receive it - it's that one, that accepted the dragEnter/dragMove events.

              Hypothetically, if you allowed both to dragEnter, which one should get the drop at the end? Both? The top one (on z-order)? The bottom one? Rolling dices?

              http://www.catb.org/~esr/faqs/smart-questions.html

              1 Reply Last reply
              0
              • O Offline
                O Offline
                Olorin5800
                wrote on last edited by
                #8

                [quote author="Volker" date="1294923392"]gnarf ... of course it does not call the dragEnterEvent method of your item if the scene already accepts the drag!

                If you eventually drop your drag - there is only one object to receive it - it's that one, that accepted the dragEnter/dragMove events.

                Hypothetically, if you allowed both to dragEnter, which one should get the drop at the end? Both? The top one (on z-order)? The bottom one? Rolling dices?[/quote]

                Yes I realized that ( after posting :D ) anyway modifing the above code like so to allow graphics scene to forward the event

                @void Scene::dragMoveEvent(QGraphicsSceneDragDropEvent *event)
                {
                QGraphicsScene::dragMoveEvent(event);
                SourceWidget *source = qobject_cast<SourceWidget *>(event->source());
                if(source) {
                event->setDropAction(Qt::CopyAction);
                event->accept();
                }

                }

                void Scene::dropEvent(QGraphicsSceneDragDropEvent *event)
                {
                QGraphicsScene::dropEvent(event);
                SourceWidget *source = qobject_cast<SourceWidget *>(event->source());
                if(source) {
                createWidget(static_castWidget::WidgetType(event->mimeData()->text().toInt()), event->scenePos());
                event->setDropAction(Qt::CopyAction);
                event->accept();
                }
                }@

                the drag enter and drop events are called for the items correctly.
                as for who accepts the drop in my application that depend on the contents of mime type (scene accepts images for example and item accept text drops).

                Thanks everyone for your help.


                My programs never have bugs, they just develop random features.

                1 Reply Last reply
                0
                • G Offline
                  G Offline
                  goetz
                  wrote on last edited by
                  #9

                  So it does work now?

                  http://www.catb.org/~esr/faqs/smart-questions.html

                  1 Reply Last reply
                  0
                  • O Offline
                    O Offline
                    Olorin5800
                    wrote on last edited by
                    #10

                    Yes it works now.


                    My programs never have bugs, they just develop random features.

                    1 Reply Last reply
                    0
                    • T Offline
                      T Offline
                      texas
                      wrote on last edited by
                      #11

                      I had the same problem. Olorin's code worked for me. Thanks for the follow up.

                      1 Reply Last reply
                      0

                      • Login

                      • Login or register to search.
                      • First post
                        Last post
                      0
                      • Categories
                      • Recent
                      • Tags
                      • Popular
                      • Users
                      • Groups
                      • Search
                      • Get Qt Extensions
                      • Unsolved