Results 1 to 1 of 1

Thread: Z-index of an item is only applied to siblings

  1. #1
    Join Date
    Jan 2011
    Posts
    5
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Z-index of an item is only applied to siblings

    I would like to implement a popup that opens up when I click one area. It would work like the popup of a combo box. I already have it more or less working but I have two problems:

    • I can use "z" to make it stay on top of other items from the same parent. However, items that are defined after the parent are displayed on top of the popup. For example:


    Qt Code:
    1. Item {
    2. Item {
    3. x: 0; y: 0; width: 200; height: 200
    4. Popup {
    5. y: parent.bottom
    6. width: 200
    7. height: 150
    8. z: 1000
    9. }
    10. }
    11. Rectangle {
    12. x: 0; y: 0; width: 500; height: 200
    13. color: "red"
    14. }
    15. }
    To copy to clipboard, switch view to plain text mode 

    The rectangle would be displayed on top of the popup even if the popup has z: 1000. Is there some way to fix it other than defining a big z index for all the ancestors of the popup?

    • I would like the popup to disappear when I click anywhere outside of the popup, like a normal QWidget popup would do. I have tried using a huge MouseArea that covers the whole screen with a big z number but it has the same problem: it works for items that are defined earlier but it doesn't for items defined later.



    Added after 1 41 minutes:


    Ok, I made it! I reparent the popup to the top-level item. This way it always stays on top of other items and both issues get solved.

    Qt Code:
    1. Component.onCompleted: {
    2. // Reparent the popup to the top-level item so that it always stays on top of all other items
    3. var topLevel = popup
    4. while(topLevel.parent) {
    5. topLevel = topLevel.parent
    6. }
    7. var coordinates = popup.mapToItem(topLevel, 0, 0)
    8. popup.parent = topLevel
    9. popup.x = coordinates.x
    10. popup.y = coordinates.y
    11. }
    To copy to clipboard, switch view to plain text mode 
    Last edited by humbleguru; 20th January 2011 at 18:19.

Similar Threads

  1. Replies: 2
    Last Post: 4th December 2010, 08:09
  2. modal that excludes parent's siblings
    By mortoray in forum Qt Programming
    Replies: 3
    Last Post: 16th October 2010, 12:33
  3. Replies: 0
    Last Post: 12th October 2010, 05:22
  4. Replies: 3
    Last Post: 11th August 2010, 13:47
  5. KDE 3 style applied to Qt 4 programs
    By alecs1 in forum KDE Forum
    Replies: 4
    Last Post: 4th December 2008, 21: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
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.