在python PyQt5中添加Qframe和Matplotlib

问题描述

我正在尝试使用Python PyQt5运行一个程序,在该程序中我将2个摄像头的ip传输到我的屏幕上,但是像这样的流(请检查第一个图片)就像给定图片中的一个一样出现蒸汽会在上半年出现,但我真正想要的是将代码的顶部布局分成两半(请查看第二张图片以更好地理解),该代码位于水平布局中,不在一起只是屏幕的第一半(我也得到了这些黑色边框,如果有人知道如何将其删除,请告诉我)。
在视频流位于底部布局的顶部布局中之后,我试图获取一个Graph和一个空窗口小部件,可以对其进行编辑以供以后使用。

预先感谢

Click here to see what output i am getting

Click here to see my desired output(what i am actually trying to get)

#this is my main window code#
import sys
import vlc
import subprocess

from PyQt5 import QtCore,QtGui,QtWidgets 

from PyQt5 import *
from PyQt5.QtGui import *
from PyQt5.QtCore import *
from PyQt5.QtWidgets import*
from PyQt5.QtWebEngineWidgets import*
from PyQt5.QtPrintSupport import*

class Window(QWidget):
    def __init__(self):
        super().__init__()
        self.setwindowTitle("Final App")
        self.setGeometry(350,150,400,400)
        self.UI()

#calling the UI fucntion which contains the layouts
    def UI(self):
        self.mainLayout=QVBoxLayout()#main layout is in Vertical Layout
        self.topLayout=QHBoxLayout()#top layout is in Horizontal layout
        self.bottomLayout=QHBoxLayout()#btm layout is in also in horizontal layout
        self.topLayout.setContentsMargins(0,0)
        #self.topLayout.setSpacing(0)


        #adding the top and bottom layout inside main layout
        self.mainLayout.addLayout(self.topLayout)
        self.mainLayout.addLayout(self.bottomLayout)

        #assigning variables to different widgets that can be added later 
        self.videoFrame1 = qframe()
        self.videoFrame2 = qframe()
        #code here to add graph#
        #graphcode=graph#
        self.text=QLabel("A widget that I can Edit LATER ")


########################################################video player 1###################################################################################


        self.videoFrame1 = qframe()
        #QWidget.setGeometry (self,100,200,1000,500)
        self.videoFrame1.setGeometry(QtCore.QRect(100,200))
        self.topLayout.addWidget(self.videoFrame1)
        self.vlcInstance = vlc.Instance(['--video-on-top'])
        self.videoPlayer = self.vlcInstance.media_player_new()
        self.videoPlayer = self.vlcInstance.media_player_new()
        self.videoPlayer.video_set_mouse_input(False)
        self.videoPlayer.video_set_key_input(False)
        #self.videoPlayer.set_mrl("rtsp://admin:admin123@192.168.1.250:554/cam/realmonitor?channel=1&subtype=0","network-caching=300")
        self.videoPlayer.set_mrl("rtsp://admin:admin123@192.168.1.251:554/cam/realmonitor?channel=1&subtype=0","network-caching=200")
        self.videoPlayer.audio_set_mute(True)
        if sys.platform.startswith('linux'): # for Linux using the X Server
            self.videoPlayer.set_xwindow(self.videoFrame1.winId())
        elif sys.platform == "win32": # for Windows
            self.videoPlayer.set_hwnd(self.videoFrame1.winId())
        elif sys.platform == "darwin": # for MacOS
            self.videoPlayer.set_nsobject(int(self.videoFrame1.winId()))

        self.videoPlayer.play()

        #########################################video player 2############################################################################################
        #frame2
        self.videoFrame2 = qframe()
        self.topLayout.addWidget(self.videoFrame2)
        self.vlcInstance1 = vlc.Instance(['--video-on-top'])
        self.videoPlayer1 = self.vlcInstance1.media_player_new()
        self.videoPlayer1 = self.vlcInstance1.media_player_new()
        self.videoPlayer1.video_set_mouse_input(False)
        self.videoPlayer1.video_set_key_input(False)
        #self.videoPlayer1.set_mrl("rtsp://admin:admin123@192.168.1.251:554/cam/realmonitor?channel=1&subtype=0","network-caching=300")
        self.videoPlayer1.set_mrl("rtsp://admin:admin123@192.168.1.250:554/cam/realmonitor?channel=1&subtype=0","network-caching=200")
        self.videoPlayer1.audio_set_mute(True)
        if sys.platform.startswith('linux'): # for Linux using the X Server
            self.videoPlayer1.set_xwindow(self.videoFrame2.winId())
        elif sys.platform == "win32": # for Windows
            self.videoPlayer1.set_hwnd(self.videoFrame2.winId())
        elif sys.platform == "darwin": # for MacOS
            self.videoPlayer1.set_nsobject(int(self.videoFrame2.winId()))

        self.videoPlayer1.play()
        ###########################################################################################################

          #calling top layout 
        self.toplayout()


        
        #calling bottom layout
        self.bottomlayout()

        #setting main layout
        self.setLayout(self.mainLayout)

        self.show()


    def toplayout(self):
        self.topLayout.setContentsMargins(10,10,20,20)
        self.topLayout.addWidget(self.
            videoFrame1)
        self.topLayout.addWidget(self.videoFrame2)

    def bottomlayout(self):
        self.bottomLayout.setContentsMargins(150,40,80)
        self.bottomLayout.addWidget(self.raddar)
        self.bottomLayout.addWidget(self.button2)


def main():
    App= QApplication(sys.argv)
    window=Window()
    sys.exit(App.exec())

if __name__ == '__main__':
    main()

这是我的另一个具有matplotlib代码文件夹:---

#this is another folder having my garph which i want to call in my main window#
import matplotlib.pyplot as plt

def UI():
    plt.figure()

    # Set x-axis range
    plt.xlim((-4,4))

    # Set y-axis range
    plt.ylim((0,8))

    #setting background color
    ax = plt.axes()
    ax.set_facecolor('black')

    # Draw lines to split quadrants
    plt.plot([0,0],[0,8],linewidth=3,color='blue' )
    plt.plot([-4,4],[4,color='blue' )
    plt.title('Quadrant plot')

    plt.show()

UI()

解决方法

嘿,所以我能够使用已有的代码来解决问题,因此我将仅在pyqt上流式传输视频,并使用子进程调用我使用MATLAB制作的.exe文件,因此在这里您确实拥有外观。(这里我现在还没有叫Subprocess)

import sys
import vlc
from PyQt5 import QtCore,QtGui,QtWidgets

from PyQt5.QtCore import *
from PyQt5.QtWidgets import *
from PyQt5.QtGui import *
from PyQt5.QtWebEngineWidgets import *
from PyQt5.QtPrintSupport import *
 
class MainWindow(QMainWindow):
    def __init__(self,*args,**kwargs):
        super(MainWindow,self).__init__(*args,**kwargs)
        #this sets the size Maximum for the main Q Frame 
        self.setWindowState(QtCore.Qt.WindowMaximized)
        #this removes the title bar of the window
        self.setWindowFlag(Qt.FramelessWindowHint)
        self.move(0,0)


        #Main Q frame defined where the HBox layout is defined
        self.mainFrame = QFrame()
        #means defining it in central widget
        self.setCentralWidget(self.mainFrame)
        #HBox Layout
        t_lay_parent = QHBoxLayout()
        #used to move the frames inside to go more up down,right,left
        t_lay_parent.setContentsMargins(0,315)
        #removes the spacing between the frames and makes it looks like that its just 1 stream
        t_lay_parent.setSpacing(0)
        
#########################################################Camera Frame 1###################################################################
        self.videoFrame = QFrame()
        QWidget.setGeometry (self,100,200,1500,1500)
        t_lay_parent.addWidget(self.videoFrame)
        self.vlcInstance = vlc.Instance(['--video-on-top'])
        self.videoPlayer = self.vlcInstance.media_player_new()
        self.videoPlayer = self.vlcInstance.media_player_new()
        self.videoPlayer.video_set_mouse_input(False)
        self.videoPlayer.video_set_key_input(False)
        #self.videoPlayer.set_mrl("rtsp://admin:admin123@192.168.1.250:554/cam/realmonitor?channel=1&subtype=0","network-caching=300")
        self.videoPlayer.set_mrl("rtsp://admin:admin123@192.168.1.251:554/cam/realmonitor?channel=1&subtype=0","network-caching=200")
        self.videoPlayer.audio_set_mute(True)
        if sys.platform.startswith('linux'): # for Linux using the X Server
            self.videoPlayer.set_xwindow(self.videoFrame.winId())
        elif sys.platform == "win32": # for Windows
            self.videoPlayer.set_hwnd(self.videoFrame.winId())
        elif sys.platform == "darwin": # for MacOS
            self.videoPlayer.set_nsobject(int(self.videoFrame.winId()))

        self.videoPlayer.play()
##########################################################Camera Frame 2#################################################################

        
        #frame2
        self.videoFrame1 = QFrame()
        t_lay_parent.addWidget(self.videoFrame1)
        self.vlcInstance1 = vlc.Instance(['--video-on-top'])
        self.videoPlayer1 = self.vlcInstance1.media_player_new()
        self.videoPlayer1 = self.vlcInstance1.media_player_new()
        self.videoPlayer1.video_set_mouse_input(False)
        self.videoPlayer1.video_set_key_input(False)
        #self.videoPlayer1.set_mrl("rtsp://admin:admin123@192.168.1.251:554/cam/realmonitor?channel=1&subtype=0","network-caching=300")
        self.videoPlayer1.set_mrl("rtsp://admin:admin123@192.168.1.250:554/cam/realmonitor?channel=1&subtype=0","network-caching=200")
        self.videoPlayer1.audio_set_mute(True)
        if sys.platform.startswith('linux'): # for Linux using the X Server
            self.videoPlayer1.set_xwindow(self.videoFrame1.winId())
        elif sys.platform == "win32": # for Windows
            self.videoPlayer1.set_hwnd(self.videoFrame1.winId())
        elif sys.platform == "darwin": # for MacOS
            self.videoPlayer1.set_nsobject(int(self.videoFrame1.winId()))

        self.videoPlayer1.play()
##########################################################################################################################################
        #adding layout inside Main Frame
        self.mainFrame.setLayout(t_lay_parent)

        #shows the Pyqt frame
        self.show()




if __name__ == "__main__":
    app = QApplication(sys.argv)
    app.setApplicationName("VLC Test")

    window = MainWindow()
    window.show()
    app.exec_()

相关问答

Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其...
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。...
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbc...