Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

QML object size within a Qt (C++) gridlayout



  • I have a Qt (C++) gridlayout. One of the objects in this layout is a QQuickWidget and one of the SizePolicies of this QQuickWidget widget is Expanding, so the size of the QQuickWidget can vary. I also construct a ChartView in QML and I display this in the QQuickWidget. I luse C++ to load the ChartView into the QQuickView and to display it. The work of the QML is to construct the ChartView. Diagramatically:

    QML ----------> Qt
    QChartView -> QQuickView

    My problem is to ensure that the ChartView fills the whole screen area available to the QQuickView. At the moment I need to specify the width and height of the Chartview in pixels and the size of the ChartView is not dynamically scaled to that of the enclosing QQuickView. See attached image.

    Screenshot from 2020-10-26 11-56-16.png image url)

    The value of parent.width is zero, so that is not useful. If I do not specify height/width of the ChartView, they are assumed to be zero so nothing is displayed.

    Is there a way to scale the ChartView to fill the whole of the available screen space?



  • @willemf Hi,

    Did you set the resizeMode of your QQuickWidget to QQuickView::SizeRootObjectToView. According to the doc it should resize your root QML element according to QQuickWidget size.



  • @Gojir4
    This was indeed the solution. Thank you very much.


Log in to reply