Quantcast
Channel: Qt DevNet forums: Qt Quick 1283365070**
Viewing all articles
Browse latest Browse all 4972

Add (and change) a component in a placeholder

$
0
0
Hi all, I am quite new to Qt programming, and I think what I try to achieve is quite simple. The application I am porting uses panels (that contain elements such as buttons and labels). Many of the panels are displayed in the center of the screen, and the application can decide to display one panel or another, depending on several actions. Only one panel is visible at any point of time. I thought that I would implement it the following way: I would like to define a “placeholder” element in my main QML layout file, let’s say: MainWindow.qml: Item {     id: window1     width: 1366     height: 768     objectName: "MainWindow"       Item {         anchors.horizontalCenter: parent.horizontalCenter         anchors.verticalCenter: parent.verticalCenter         width: 490         height: 445         objectName: "CenterPanel"     } } … And be able, from the C++ code, to dynamically add (and replace) a child to this container placeholder element each time I want to display a panel. This child would simply be a new component, loaded from a QML file depending on the panel that is required to be displayed: PanelA.qml: import QtQuick 2.2 import QtQuick.Window 2.1 import QtQuick.Controls 1.2   Item {     objectName: "PanelA"     anchors.fill: parent       ... } I expect something like that in my C++ code: pPanelA = <LOAD PANEL FROM QML FILE>; pCenterPanel->removeChild(); pCenterPanel->addChild( pPanelA ); How can I achieve that? Thank you.

Viewing all articles
Browse latest Browse all 4972