QCameraViewFinder weird layout on iOS



  • I want to show a simple viewfinder for the camera on an iPhone 6 with Qt for iOS. Everything is working but the viewfinder is shown in the upper left corner and very small (i am simply adding the viewfinder to the central widget which occupies the whole Main Window). I also tried viewfinder->setFixedHeight (and width); this changes the viewfinder's size but the position is still offset... Anybody know how to fix this?

    Here's my code (copied from the docs):

        ui->setupUi(this);
    
        camera = new QCamera;
        viewfinder = new QCameraViewfinder(ui->centralWidget);
        viewfinder->show();
        camera->setViewfinder(viewfinder);
        imageCapture = new QCameraImageCapture(camera);
        camera->setCaptureMode(QCamera::CaptureStillImage);
    
        camera->start();
    
        //on half pressed shutter button
        camera->searchAndLock();
    
        //on shutter button pressed
        imageCapture->capture();
    
        //on shutter button released
        camera->unlock();
    

  • Lifetime Qt Champion

    Hi and welcome to devnet,

    You should put your viewFinder in a layout in your widget otherwise it's your responsibility to give it a sensible size and position.



  • Thank you @SGaist :-) And thank you very much for taking your time to respond to my question.

    I should have thought of adding the widget to a layout. In a new attempt i added a vertical layout to my central widget in Qt Designer, to which i then added the viewfinder programmatically (code below). Nothing else is added to the vertical layout. Now the viewfinder is larger but shown in the bottom half of the screen and offset to the right (some part of it ends up outside of the screen), with the phone in upright position.

    Appreciate your help if you have time!

        ui->setupUi(this);
    
        camera = new QCamera;
        viewfinder = new QCameraViewfinder();
        imageCapture = new QCameraImageCapture(camera);
    
        camera->setViewfinder(viewfinder);
        camera->setCaptureMode(QCamera::CaptureStillImage);
    
        ui->verticalLayout->addWidget(viewfinder);
        viewfinder->show();
        camera->start();
    
        //on half pressed shutter button
        camera->searchAndLock();
    
        //on shutter button pressed
        imageCapture->capture();
    
        //on shutter button released
        camera->unlock();
    

  • Lifetime Qt Champion

    QCameraViewFinder might have some trouble on iOS, try setting the size policy to Fixed both horizontally and vertically.



  • @SGaist Thank you! It works OK now by setting fixed width and height!

    Works even better with fixed size policy for the viewfinder; i.e. by adding:

    viewfinder->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed)
    


  • Setting the size policy to fixed solved the layout issue. However, with that fix, frames are updated very slowly (updating is clearly faster without setting the fixed size policy). Anybody know a fix?
    Thanks :-)


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.