0
votes

I have an Qt 5.6.0 application on android with a QQuickView with transparent background which draw some qml and a pure android SurfaceView which is supposed to display a video in background.

At startup, everything is good. My video is playing in background and my qml components are displayed in foreground.

My problem is when my activity is paused then resume, every time the video is displayed on top from my qml. After research I think it's because the SurfaceView created by Qt to display the qml and my SurfaceView created to display the video are in the same "z area". So the render order is undefined.

I would like move the Qt SurfaceView to the ZOrderMediaOverlay area by setting the ZOrderMediaOverlay to true but I have to set it at SurfaceView creation.

Is there a way to set my z order directly from c++ when I create my QQuickView ? Or is there another way ?

I have a custom activity which inherits from QtActivity, but the SurfaceView is not created yet in the onCreate function. I can access to the Qt SurfaceView when I create my SurfaceView for video but the Qt's one is already created and set the ZOrderMediaOverlay has no effect.

Thanks a lot for your help :)

Edit: regarding to the source code, simply set the QQuickView's flag Qt::WindowStayOnTopHint to true should create the surface with ZOrderMediaOverlay set to true but it doesn't seem to work. The video surface is drawn above the qml surface after resume until the video surface is destroyed and recreated.

1

1 Answers

1
votes

You must also insert your SurfaceView into Android's ViewGroup container, that Qt uses for widgets already, but your SurfaceView must be behind QML's frame:

public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    // Init surface
    surfaceView = new SurfaceView(this);

    // It displaces original QML view.
    // setContentView(surfaceView);

    // Add SurfaceView to view container
    View view = getWindow().getDecorView().getRootView();
    LinearLayout mainLinearLayout = (LinearLayout)(((ViewGroup)view).getChildAt(0));
    FrameLayout mainFrameLayout = (FrameLayout)(mainLinearLayout.getChildAt(1));
    mainFrameLayout.addView(surfaceView, 0);
}

I don't recommend to use QQuickView for increasing performance, only ApplicationWindow on QML side ;)