[HOW-TO] PyQt5 QGlPicamera2 always windowed
See original GitHub issueI am trying to use the QGlPicamera2
widget inside a custom widget.
Everything works well following the documentation, but as I try to move the implementation inside a custom widget the Preview will be rendered in a new window and I can’t figure out what I am missing.
In this slice of code the timer updates the countdown timer and triggers the switch_mode_and_capture_file()
process with the wait()
on the camera…
It works and the picture was taken, but the preview was opened into a new window.
The custom camera widget (which will be rendered in stacked layout):
class CustomCameraWidget(QtWidgets.QWidget):
def __init__(self, signals, picam2, *args, **kwargs):
super(CustomCameraWidget, self).__init__(*args, **kwargs)
self.picam2 = picam2
self._countdown = 5
self._timer = QTimer()
self._timer.timeout.connect(self.on_timeout)
self._layout = QVBoxLayout()
self._layout.setContentsMargins(0, 0, 0, 0)
self._layout.setSpacing(0)
layout = QStackedLayout()
layout.setStackingMode(QStackedLayout.StackingMode.StackAll)
self.camera_view = QGlPicamera2(self.picam2, width=800, height=600, keep_ar=False)
self.camera_view.done_signal.connect(self.on_capture_done)
layout.addWidget(self.camera_view)
self.countdown_label = QLabel()
self.countdown_label.setText(f"{self._countdown}")
layout.addWidget(self.countdown_label)
self._layout.addLayout(layout)
buttons_layout = QHBoxLayout()
self.abort_button = QPushButton("Undo")
self.abort_button.clicked.connect(self.undo_button_clicked)
buttons_layout.addWidget(self.abort_button)
self._layout.addLayout(buttons_layout)
self.setLayout(self._layout)
An extract of the main:
if __name__ == "__main__":
picam2 = Picamera2()
picam2.configure(picam2.create_preview_configuration())
app = QApplication(sys.argv)
window = CustomMainWindow( picam2)
picam2.start()
window.show()
app.exec()
Any suggestion or working example?
Issue Analytics
- State:
- Created 10 months ago
- Comments:5
Top Results From Across the Web
Multiple windows in PyQt5 - Python GUIs
One solution is to simply check whether the window has already being created before creating it. The example below shows this in action....
Read more >Use PyInstaller to build PyQt5 with QML in --onefile
I found a workaround with Pyinstaller 3.3.1 and PyQt5 >= 5.11 to solve this problem. Use pyrcc5 to compile QML files and import...
Read more >PyQt5 – How to open window in maximized format?
In this article we will see how to make a window to open in maximized format, which refer to full screen display window....
Read more >picamera2 - PyPI
Use the QtPreview or QtGlPreview class. This starts a preview window implemented using PyQt and the Qt event loop drives the camera. Use...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Thanks for the update. I’ll close this issue for now, but we’ll leave it on our list to have another look at GL rendering at some point.
Thanks for the help. I leave a note here:
Using
QStackedLayout
withQGlPicamera2
needs to specify the parent widget to work, but for some reason the GL stream is not rendered anymore. Moving to useQPicamera2
instead ofQGlPicamera2
solve this issue but i don’t want to sacrifice the usage of the GPU.Unfortunately I’m not experienced with OpenGL, Qt nor Python so I can’t investigate more.
For now I changed the design of the App to not use
QStackedLayout
where the camera needs to be rendered.