Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. How do you add a Camera class to a .ui file correctly?
QtWS25 Last Chance

How do you add a Camera class to a .ui file correctly?

Scheduled Pinned Locked Moved Solved General and Desktop
qcameraqcameraviewfindvideowebcampromote
2 Posts 1 Posters 704 Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • A Offline
    A Offline
    arjun98
    wrote on 30 Apr 2021, 23:04 last edited by
    #1

    I have a general ui page (video_display.ui) (Qt designer) with a layout and several components. I have set a blank widget named video within that page and promote it to class QCameraViewfinder. If I run the following code from within the cpp (video_display.cpp) file, I get the result I want.

    Video_display::Video_display(QWidget *parent) :
        QWidget(parent),
        ui(new Ui::Video_display)
    {
        ui->setupUi(this);
    ui->set
     mCamera = new QCamera(this);
     mCameraViewfinder = ui->video;
     mCamera->setViewfinder(mCameraViewfinder);
     ui->video->show();
     mCamera->start();
    }
    

    However, I want to implement everything related to the camera in a separate class.
    So instead of promoting to QCameraViewfinder, I promote it to Camera which is a custom class.

    Camera::Camera(QWidget *parent) : QWidget(parent)
    {
    
         mCamera = new QCamera();
         mCameraViewfinder = new QCameraViewfinder(this);
         mCamera->setViewfinder(mCameraViewfinder);
         mCamera->start();
    }
    

    The problem with this is that while the camera is in the correct location it is not scaled to fit within the video widget thus only displaying a portion of the video screen.

    If I add the following line of code:

    mCamerViewfinder->show();
    

    The video is only displayed in a small frame within the video widget location.

    Any guidance on the matter would be very helpful.
    Thank you,
    Arjun

    1 Reply Last reply
    0
    • A Offline
      A Offline
      arjun98
      wrote on 1 May 2021, 12:24 last edited by
      #2

      I added the following two lines of code and it worked:

           QHBoxLayout *camera_layout = new QHBoxLayout(this);
           mCamera = new QCamera();
           mCameraViewfinder = new QCameraViewfinder();
           camera_layout->addWidget(mCameraViewfinder);
           mCamera->setViewfinder(mCameraViewfinder);
           mCamera->start();
      

      And it worked

      1 Reply Last reply
      0

      2/2

      1 May 2021, 12:24

      • Login

      • Login or register to search.
      2 out of 2
      • First post
        2/2
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • Users
      • Groups
      • Search
      • Get Qt Extensions
      • Unsolved