Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. QML and Qt Quick
  4. [Solved] Paint order / Clipping?
Forum Updated to NodeBB v4.3 + New Features

[Solved] Paint order / Clipping?

Scheduled Pinned Locked Moved QML and Qt Quick
5 Posts 2 Posters 1.7k 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.
  • K Offline
    K Offline
    kaivolde
    wrote on last edited by
    #1

    Hi folks,

    hope someone can help me with the following problem:

    setup:

    • one big rectangle as a background
    • two rectangles "left" and "right" side by side on top of the first rectangle
    • some smaller "drag"-rectangles on top of the left rectangle. These small rectangles should be
      moved by drag-and-drop to the right side rectangle.

    problem:
    the small "drag"-rectangles are only visible if they are moved on top of the left- or background-rectangle. If I move it on top of the right-rectangle it gets invisible and is painted behind the right rectangle.

    I think it has nothing to do with z-ordering. I tried to give the small rects big z-values but without any effect.

    Do I have to dynamically reparent the moved rectangle?
    How can this be done?

    Many thanks in advance.
    Best regards
    Kai

    1 Reply Last reply
    0
    • R Offline
      R Offline
      Rolias
      wrote on last edited by
      #2

      Do you have to have the draggable rectangle as a child of the left rectangle?
      If you just put the left right and drag rectangle all as direct children of your "big" rectangle it would work.

      If you have to have the draggable rect as a child of the left or right you can reparent it by reassigning the parent property to the id of the right rectangle.
      @dragRectId.parent = rightId@

      How you do that might be tricky if you try to use the mouse position since positioning is relative to the parent. I just did a quick test with a draggable rectangle and a key handler. When I hit the key I reparent to the right rectangle.

      <shameless plug> I cover doing dynamic adjustment to the color property of a dragged rectangle in my Qt Quick Fundamentals course on Pluralsight which just went live this week. Very similar to what you're after.</shameless plug>

      Check out my third course in the trilogy on Qt
      "Integrating Qt Quick with C++"
      http://bit.ly/qtquickcpp
      published by Pluralsight

      1 Reply Last reply
      0
      • K Offline
        K Offline
        kaivolde
        wrote on last edited by
        #3

        Hi Rolias,
        thanks for your answer. It already helped a little bit. I think I have to do the reparenting. Maybe the onEntered-handler of a DropArea is a suitable place for this. I will try it out.

        But one thing is strange: When I want to move an item around by dragging it with the mouse, I don't want that it is obscurred by other items of a scene. As long as the moving is active it should always be visible on top of all other items. Is there a way to implement such a behaviour? Do I have to temporarily reparent the item to a global root? Is there a global root?

        1 Reply Last reply
        0
        • R Offline
          R Offline
          Rolias
          wrote on last edited by
          #4

          The "drag and drop example code":http://qt-project.org/doc/qt-5/qtquick-draganddrop-example.html should do what you want. Look for how they use states and the ParentChange object to re-parent the drag item to the root while it's being dragged.

          If this doesn't work, either post some code or specify what you're doing differently that doesn't work.

          Check out my third course in the trilogy on Qt
          "Integrating Qt Quick with C++"
          http://bit.ly/qtquickcpp
          published by Pluralsight

          1 Reply Last reply
          0
          • K Offline
            K Offline
            kaivolde
            wrote on last edited by
            #5

            Ok. This works now. As long as the drag is active I have to reparent the dragged rect to something global (I introduced a global background rect for that purpose).

            Thanks for the help.

            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