1

嗨,我需要调整 ScrollView 的视口,使其显示在屏幕中间。我尝试了所有我能想到的属性。

    Page *page = new Page();
Container *container = new Container();
AbsoluteLayout *absoluteLayout = new AbsoluteLayout();
container->setLayout(absoluteLayout);
for(int y=0;y<1536;y+=256)
{
    for(int x=0;x<1536;x+=256)
    {
        AbsoluteLayoutProperties *imageProperties = AbsoluteLayoutProperties::create().x(x).y(y);
        ImageView *imageView = ImageView::create().layoutProperties(imageProperties);
        imageView->setImage(Image("assets/tile256.jpg"));
        container->add(imageView);
    }
}
ScrollView *scrollView = ScrollView::create(container).preferredSize(300,300);
scrollView->setHorizontalAlignment(HorizontalAlignment::Center);
scrollView->setVerticalAlignment(VerticalAlignment::Center);
scrollView->setMaxHeight(300);
scrollView->setMaxWidth(300);
ScrollViewProperties *scrollViewProperties = scrollView->scrollViewProperties();
scrollViewProperties->setScrollMode(ScrollMode::Both);
scrollView->zoomToPoint(300,500,1);
QRectF qRectf = scrollView->viewableArea();
qRectf.setX(300);
qRectf.setY(300);
page->setContent(scrollView);
app->setScene(page);

这是我尝试过的。

4

1 回答 1

0

要将控件停靠在特定区域,请设置容器 DockLayout 的布局并在其中添加控件。因此,即使控件展开/收缩,它也会停靠在指定区域。在这里,在 Container 中添加 ScrollView 并将该容器设置为页面的内容。

Page *page = new Page();

Container *mainContainer = new Container(); //This is the main container of the page
mainContainer->setLayout(new DockLayout()); //To dock scroll view at center of the screen

Container *container = new Container();
...
...
...
mainContainer->add(scrollView);//Add scroll view to the main container
page->setContent(mainContainer);//Set main container as the content
app->setScene(page);
于 2012-12-31T13:06:17.313 回答