Important: Please read the Qt Code of Conduct -

How to change application window z index

  • I was trying to get native iOS player as a custom QML component and managed to do it thanks to this. However I'm facing a problem with z order of the component.

    Component constructor:

    MyVideoView::MyVideoView(QQuickItem *parent /*= 0*/)
        : QQuickItem(parent)
        , m_view(0)
        connect(this, SIGNAL(windowChanged(QQuickWindow*)), this, SLOT(onWindowChanged(QQuickWindow*)));
        connect(this, SIGNAL(visibleChanged()), this, SLOT(onVisibleChanged()));

    onWindowChanged implementation:

    void MyVideoView::onWindowChanged(QQuickWindow* window)
        if(!m_view) {
        if (window != 0) {
            UIView *parentView = reinterpret_cast<UIView *>(window->winId());
                    AVPlayer *_player;
                    AVURLAsset *_asset;
                    AVPlayerItem *_playerItem;
                    AVPlayerLayer *m_playerLayer;
                    _player = [[AVPlayer alloc] init];
                    NSURL *baseURL = [[NSURL alloc] initWithString: @""];
                    _asset = [AVURLAsset assetWithURL:baseURL];
                    _playerItem = [AVPlayerItem playerItemWithAsset: _asset];
                    [_player replaceCurrentItemWithPlayerItem:_playerItem];
                    m_playerLayer = [AVPlayerLayer playerLayerWithPlayer:_player];
                    m_playerLayer.frame = CGRectMake(this->x(), this->y(), this->width(), this->height());
                    [parentView.layer addSublayer:m_playerLayer ];
                    [_player play];
        } else {
            [m_view removeFromSuperView];

    Whit this I can use the component in my application which is an ApplicationWindow, but the issue is, the component is always on top, covering the whole application even if I set:

    MyVideoView {
        width: 300
        height: 200

    Or put z of another component to e.g. 300.
    I assume it's because of QQuickWindow or caused by UIView.
    MyVideoView is placed inside an Item component

    What I would want to achieve is to:

    • either make it possible to set the components z order
    • or get the component "behind" the application (creating transparent part on my app so the video is visible, not the best solution but I'm running out of options)

    Is there any way to achieve one of those, or can it be done if the component is something else besides a QQuickItem, since the only part I actually need is the player layer, as I'll create a custom playback control interface?