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. Howto Drop into QGraphicsView/QGraphicsScene
Forum Updated to NodeBB v4.3 + New Features

Howto Drop into QGraphicsView/QGraphicsScene

Scheduled Pinned Locked Moved General and Desktop
7 Posts 5 Posters 8.7k Views 2 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.
  • S Offline
    S Offline
    sirblack
    wrote on last edited by
    #1

    Hello,
    I am quite new to Qt.
    Basically I want to create a List holding Widgets derived from QGraphicsSVGItem.
    Now I want to have a QGraphicsScene and a QGraphicsView displaying the scene.

    It should be possible to drop my SvgItem into the GraphicsScene.
    I have a hard time to understand what exactly I need to do.

    I see, that I cannot acceptDrops directly inside the scene.

    So could I create some kind of background item that resides also in the scene and will accept the drops?

    Is this the right approach or can I somehow accept the incoming Items in the GraphicsView.

    Thanks.

    A 1 Reply Last reply
    0
    • F Offline
      F Offline
      Franzk
      wrote on last edited by
      #2

      Set acceptDrops on the graphics view. Then reimplement QGraphicsScene's dragEnterEvent(), dragMoveEvent(), dragLeaveEvent() and dropEvent() according to your needs. You probably need to accept the drag action in dragEnterEvent() and dragMoveEvent(). This is done in the same way you would implement them on a widget. Then implement dropEvent() to handle the actual drop.

      "Horse sense is the thing a horse has which keeps it from betting on people." -- W.C. Fields

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

      H 1 Reply Last reply
      0
      • L Offline
        L Offline
        LiamMaru
        wrote on last edited by
        #3

        Funny, I just wrote code to do exactly this. I can add to Franzk's post, you need to accept the event in the enter and ove events if it's valid. Otherwise dropEvent won't be called when the user releases the mouse.

        1 Reply Last reply
        0
        • S Offline
          S Offline
          sirblack
          wrote on last edited by
          #4

          thanks a bunch. that did it. I found it confusing, that you accept the drops in the graphicsview and not in the scene.

          Thank you.

          1 Reply Last reply
          0
          • F Offline
            F Offline
            Franzk
            wrote on last edited by
            #5

            It's not so confusing if you remember that the widget is the object that actually handles the events. In this case however, the events are relayed to the scene.

            "Horse sense is the thing a horse has which keeps it from betting on people." -- W.C. Fields

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

            1 Reply Last reply
            0
            • F Franzk

              Set acceptDrops on the graphics view. Then reimplement QGraphicsScene's dragEnterEvent(), dragMoveEvent(), dragLeaveEvent() and dropEvent() according to your needs. You probably need to accept the drag action in dragEnterEvent() and dragMoveEvent(). This is done in the same way you would implement them on a widget. Then implement dropEvent() to handle the actual drop.

              H Offline
              H Offline
              hannylove
              wrote on last edited by
              #6

              @Franzk said in Howto Drop into QGraphicsView/QGraphicsScene:

              Set acceptDrops on the graphics view. Then reimplement QGraphicsScene's dragEnterEvent(), dragMoveEvent(), dragLeaveEvent() and dropEvent() according to your needs. You probably need to accept the drag action in dragEnterEvent() and dragMoveEvent(). This is done in the same way you would implement them on a widget. Then implement dropEvent() to handle the actual drop.

              thanks a lot for your answer! confusing me long long time why dropEvent in QGraphicsView alway not active and now i finally know i missing two event->accept() in that two function

              1 Reply Last reply
              0
              • S sirblack

                Hello,
                I am quite new to Qt.
                Basically I want to create a List holding Widgets derived from QGraphicsSVGItem.
                Now I want to have a QGraphicsScene and a QGraphicsView displaying the scene.

                It should be possible to drop my SvgItem into the GraphicsScene.
                I have a hard time to understand what exactly I need to do.

                I see, that I cannot acceptDrops directly inside the scene.

                So could I create some kind of background item that resides also in the scene and will accept the drops?

                Is this the right approach or can I somehow accept the incoming Items in the GraphicsView.

                Thanks.

                A Offline
                A Offline
                Asperamanca
                wrote on last edited by
                #7
                This post is deleted!
                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