首页 > 解决方案 > How to put a widget in a tab in PyQt5

问题描述

I'm currently working on a security camera project. It has mainly two functions:

  1. Catches the videoframes with faces
  2. Shows the captured frames

I succesfully wrote the code for both classes but a problem occurs when I try to put 2nd function

class Iwindow(QMainWindow, gui):
def __init__(self, parent=None):
    QMainWindow.__init__(self, parent)
    self.setupUi(self)
    self.cntr, self.numImages = -1, -1  # self.cntr have the info of which image is selected/displayed
    self.image_viewer = ImageViewer(self.label)
    self.showMaximized()
    self.selectFolder.clicked.connect(self.selectDir)
    self.nextImage.clicked.connect(self.nextImg)
    self.prevImage.clicked.connect(self.prevImg)
    self.listView.clicked.connect(self.item_click)

This is from the code for image displaying. When I try to put image viewer to a tab widget in another program it doesn't go under the tab when I try to do it.

#Create second tab
    self.tab2.layout = QVBoxLayout(self)
    self.imgViewWidget = Iwindow()
    self.tab2.layout.addWidget(self.imgViewWidget)
    self.tab2.layout = QVBoxLayout(self)

this is when I try to call widget. Could anyone help me?

this is the final product of my code

标签: pythonpyqtpyqt5

解决方案


推荐阅读