我正在尝试将ImageView添加到容器中,因为它不会出现在屏幕上。 容器是在QML中创建的,但我希望将图像添加到.CPP文件中。
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 :(得分: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);
答案 1 :(得分:0)
我建议在WebView
中显示图片祝你好运