BlackBerry 10 - Adding ImageView to the container

advertisements

I'm trying to add an ImageView to container, by it doesn't appear on the screen. Container is created in QML, but I want image to be added in .CPP file.

ApplicationUI.cpp:

 ApplicationUI::ApplicationUI(bb::cascades::Application *app)
   : QObject(app)
   {
QmlDocument *qml = QmlDocument::create("asset:///main.qml").parent(this);

AbstractPane *root = qml->createRootObject<AbstractPane>();

ImageView* imageView1 = new ImageView();
imageView1->setImage(Image("asset:///icon.png"));

Page *page = qml->createRootObject<Page>();
Container *_mRootContainer = page->findChild<Container*>("rootContainer");

_mRootContainer->add( imageView1 );
app->setScene(root);

 }

main.xml:

import bb.cascades 1.0

Page {
    Container {
        objectName: "rootContainer"
        Label {
            text: "First page"
        }
    }
 }

Thanks in advance ;)


You can create an image container in your .CPP file and then create/add all your images to your container. Eg: using the DockLayout here for images ontop of each other and centered them within parent container.

//Create the images container and center it within parent container

    Container *imageContainer = new Container();
    imageContainer->setLayout(new DockLayout());
    imageContainer->setHorizontalAlignment(HorizontalAlignment::Center);

//Create the image (add the image file into asset folder)

    ImageView* imageView1 = ImageView::create("asset:///icon.png");

//Align/center image horizontally and vertically within parent container

    imageView1->setHorizontalAlignment(HorizontalAlignment::Center);
    imageView1->setVerticalAlignment(VerticalAlignment::Center);

//Add images to image container

    imageContainer->add(imageView1);