I am developing an application that includes displaying the feed from an attached camera. The application starts up with the video display only on half the window. The user can then click a button that toggles the video between full screen and the half window. It works great, however the aspect ratio is not being applied. I tried setting the aspect ratio mode on the QCameraViewfinder widget but it made no differed. I really need some help with this. I will attempt to show the parts of the code that applies.

Here is the ui file:

Qt Code:
  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <ui version="4.0">
  3. <class>MainWindow</class>
  4. <widget class="QMainWindow" name="MainWindow">
  5. <property name="geometry">
  6. <rect>
  7. <x>0</x>
  8. <y>0</y>
  9. <width>1024</width>
  10. <height>768</height>
  11. </rect>
  12. </property>
  13. <property name="windowTitle">
  14. <string>LEAP</string>
  15. </property>
  16. <widget class="QWidget" name="centralWidget">
  17. <property name="minimumSize">
  18. <size>
  19. <width>1024</width>
  20. <height>768</height>
  21. </size>
  22. </property>
  23. <property name="maximumSize">
  24. <size>
  25. <width>1024</width>
  26. <height>768</height>
  27. </size>
  28. </property>
  29. <widget class="QWidget" name="horizontalLayoutWidget">
  30. <property name="geometry">
  31. <rect>
  32. <x>0</x>
  33. <y>0</y>
  34. <width>1024</width>
  35. <height>768</height>
  36. </rect>
  37. </property>
  38. <layout class="QHBoxLayout" name="horizontalLayout">
  39. <property name="spacing">
  40. <number>2</number>
  41. </property>
  42. <item>
  43. <widget class="MovingMap" name="mapFrame" native="true">
  44. <property name="minimumSize">
  45. <size>
  46. <width>512</width>
  47. <height>768</height>
  48. </size>
  49. </property>
  50. <property name="maximumSize">
  51. <size>
  52. <width>1024</width>
  53. <height>768</height>
  54. </size>
  55. </property>
  56. </widget>
  57. </item>
  58. <item>
  59. <widget class="QCameraViewfinder" name="cameraFrame" native="true">
  60. <property name="minimumSize">
  61. <size>
  62. <width>512</width>
  63. <height>768</height>
  64. </size>
  65. </property>
  66. <property name="maximumSize">
  67. <size>
  68. <width>1024</width>
  69. <height>768</height>
  70. </size>
  71. </property>
  72. </widget>
  73. </item>
  74. </layout>
  75. </widget>
  76. </widget>
  77. </widget>
  78. <layoutdefault spacing="6" margin="11"/>
  79. <customwidgets>
  80. <customwidget>
  81. <class>QCameraViewfinder</class>
  82. <extends>QWidget</extends>
  83. <header>qcameraviewfinder.h</header>
  84. <container>1</container>
  85. </customwidget>
  86. <customwidget>
  87. <class>MovingMap</class>
  88. <extends>QWidget</extends>
  89. <header>movingmap.h</header>
  90. <container>1</container>
  91. </customwidget>
  92. </customwidgets>
  93. <resources/>
  94. <connections/>
  95. </ui>
To copy to clipboard, switch view to plain text mode 

I have a function that starts up the camera:

Qt Code:
  1. void MainWindow::startCamera()
  2. {
  3. qDebug() << "At MainWindow::startCamera()";
  4.  
  5. QByteArray cameraDevice = QCamera::availableDevices()[0];
  6. camera = new QCamera(cameraDevice);
  7. camera->setViewfinder(ui->cameraFrame);
  8. ui->cameraFrame->setAspectRatioMode(Qt::KeepAspectRatioByExpanding);
  9. camera->setCaptureMode(QCamera::CaptureStillImage);
  10. camera->start();
  11. }
To copy to clipboard, switch view to plain text mode 

The result is the video fills it's widget. But it is stretched top to bottom instead of expanding the video output so the image is displayed according to the proper aspect ratio.

What am I doing wrong? Is it the layout that is causing the problem? Should I capture the image and trim it in my own code before it is passed to the display? I can think of a couple possibilities but I'd prefer to not put extra processing in my code if it not necessary.