Search code examples
c++qtblackberryblackberry-10blackberry-cascades

Display buttons in the middle of the screen in BlackBerry 10 app using qt c++


I wanted a screen in my application which should look like this:

enter image description here

This means the button in the screen should appear in the centre for screen both horizontally and vertically.

Does anyone how to do it. I have written the following code but its not working.

Container *contentContainer = new Container();
contentContainer->setLayout(StackLayout::create());  
//contentContainer->setVerticalAlignment(VerticalAlignment::Center);
contentContainer->setHorizontalAlignment(HorizontalAlignment::Center);

Button* submitButton =  new Button();
submitButton->setText("Submit");

Button* cancelButton =  new Button();
cancelButton->setText("Cancel");

contentContainer->add(submitButton);
contentContainer->add(cancelButton);

Page * testPage = new Page();
testPage ->setContent(contentContainer);

Sheet *testSheet = new Sheet();
testSheet->setContent( LoginSheetPage );

testSheet->open();

Solution

  • To get it center , First you have to create container with docklayout() and inside this container, you have to create stacklayout() with buttons and set docklayout() container as a content of Page.

    Container *contentContainer = new Container();
    contentContainer->setLayout(StackLayout::create());  
    contentContainer->setVerticalAlignment(VerticalAlignment::Center);
    contentContainer->setHorizontalAlignment(HorizontalAlignment::Center);
    
    Button* submitButton =  new Button();
    submitButton->setText("Submit");
    
    Button* cancelButton =  new Button();
    cancelButton->setText("Cancel");
    
    contentContainer->add(submitButton);
    contentContainer->add(cancelButton);
    
    Container *rootContainer = new Container();
    rootContainer->setLayout(DockLayout::create());  
    rootContainer->setVerticalAlignment(VerticalAlignment::Fill);
    rootContainer->setHorizontalAlignment(HorizontalAlignment::Fill);
    rootContainer->add(contentContainer);
    
    Page * testPage = new Page();
    testPage ->setContent(rootContainer);