2013-07-09 106 views
0

我試圖將ImageView添加到容器,通過它不出現在屏幕上。 容器是在QML中創建的,但我希望將圖像添加到.CPP文件中。黑莓10 - 將ImageView添加到容器

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" 
     } 
    } 
} 

在此先感謝;)

回答

0

您可以在.cpp文件中創建一個圖像容器,然後創建/將所有圖像添加到您的容器中。例如:在這裏使用DockLayout來顯示彼此的圖像並將它們居中放在父容器中。

//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);