How to Open a Qprocess that is GUI based
-
I would like to open a process which has its own GUI based interface inside my app. For example I have the a label called container and I like to add the output of the command evince -s mypdf.pdf inside that container.
import sys from PyQt5.QtCore import QProcess from PyQt5.QtWidgets import QApplication, QMainWindow, QLabel class MainWindow(QMainWindow): def __init__(self): super().__init__() self.container = QLabel("PDF Area") self.process = QProcess() self.setCentralWidget(self.container) def run(self, command): ''' .... Code to attach command output ie a GUI window inside self.container .... ''' self.process.start(command) app = QApplication(sys.argv) window = MainWindow() window.show() window.run('evince -s mypdf.pdf') app.exec() -
I would like to open a process which has its own GUI based interface inside my app. For example I have the a label called container and I like to add the output of the command evince -s mypdf.pdf inside that container.
import sys from PyQt5.QtCore import QProcess from PyQt5.QtWidgets import QApplication, QMainWindow, QLabel class MainWindow(QMainWindow): def __init__(self): super().__init__() self.container = QLabel("PDF Area") self.process = QProcess() self.setCentralWidget(self.container) def run(self, command): ''' .... Code to attach command output ie a GUI window inside self.container .... ''' self.process.start(command) app = QApplication(sys.argv) window = MainWindow() window.show() window.run('evince -s mypdf.pdf') app.exec()@qtbuddy
Hello and welcome.If you are determined to use
evincefor viewing PDF then my understanding is that you must launch it viaQProcess, discover which window id it has used (somehow) and then embed that into a Qt widget via the code shown at e.g. https://stackoverflow.com/a/33760341/489865. I presume that "re-parents" the X window into the widget.If you do not require the
evinceexternal viewer then you might consider one of the ways of displaying PDF offered by Qt. There is https://doc.qt.io/qt-6/qtpdf-pdfviewer-example.html and https://www.kdab.com/browse-pdfs-in-a-qt-widgets-application/ among others, the Poppler libraries, andQWebEngineViewcan also be used to view PDF.