小部件跨越 Pyqt5 上的选项卡

Widgets cross over the tab on Pyqt5

我正在尝试构建一个简单的桌面应用程序,它可以在一个地方显示和播放所有电影。这个应用程序包括几个选项卡,其中包含不同类别的电影。

问题是我放在选项卡中的小部件 windows 越过选项卡标题。不知道为什么。

这是我的代码:

import sys
from PyQt5.QtWidgets import *
from PyQt5.QtGui import *
from PyQt5.QtCore import *

class Filmler(QTabWidget):
    def __init__(self):
        super().__init__()

        self.setWindowTitle("Filmler")
        self.setWindowIcon(QIcon("film.jpg"))
        self.setGeometry(200,100,1000,500)

        self.tab1 = QWidget()
        self.tab2 = QWidget()
        self.tab3 = QWidget()
        self.tab4 = QWidget()

        self.tab1UI()
        self.tab2UI()
        self.tab3UI()
        self.tab4UI()

        self.addTab(self.tab1, "Hollywood")
        self.addTab(self.tab2, "Bollywood")
        self.addTab(self.tab3, "Uyghur")
        self.addTab(self.tab4, "Zumra'nin Filmleri")

        self.show()

    def tab1UI(self):
        # adding variables
        # 1st movie
        movie1_poster = QLabel()
        movie1_poster.setPixmap(QPixmap("equalizer2.jpg"))
        movie1_name = QLabel("Equalizer 2")
        movie1_name.setAlignment(Qt.AlignCenter)
        movie1_name.setFont(QFont("Times", 13))
        movie1_link = QPushButton("izle")
        vbox1 = QVBoxLayout()
        vbox1.addWidget(movie1_name)
        vbox1.addWidget(movie1_poster)
        vbox1.addWidget(movie1_link)
        vbox1.addStretch()

        hbox = QHBoxLayout()
        hbox.addLayout(vbox1)
        hbox.addStretch()

        self.setLayout(hbox)

    def tab2UI(self):
        pass



    def tab3UI(self):
        pass



    def tab4UI(self):
        pass


app = QApplication(sys.argv)
filmler = Filmler()
sys.exit(app.exec_())

这是结果。

将父 self.tab1 设置为 QHBoxLayout

import sys
from PyQt5.QtWidgets import *
from PyQt5.QtGui import *
from PyQt5.QtCore import *

class Filmler(QTabWidget):
    def __init__(self):
        super().__init__()

        self.setWindowTitle("Filmler")
        self.setWindowIcon(QIcon("film.jpg"))
        self.setGeometry(200,100,1000,500)

        self.tab1 = QWidget()
        self.tab2 = QWidget()
        self.tab3 = QWidget()
        self.tab4 = QWidget()

        self.tab1UI()
        self.tab2UI()
        self.tab3UI()
        self.tab4UI()

        self.addTab(self.tab1, "Hollywood")
        self.addTab(self.tab2, "Bollywood")
        self.addTab(self.tab3, "Uyghur")
        self.addTab(self.tab4, "Zumra'nin Filmleri")

        self.show()

    def tab1UI(self):
        # adding variables
        # 1st movie
        movie1_poster = QLabel()
        movie1_poster.setPixmap(QPixmap("lena.jpg"))
        movie1_name = QLabel("Equalizer 2")
        movie1_name.setAlignment(Qt.AlignCenter)
        movie1_name.setFont(QFont("Times", 13))
        movie1_link = QPushButton("izle")
        vbox1 = QVBoxLayout()
        vbox1.addWidget(movie1_name)
        vbox1.addWidget(movie1_poster)
        vbox1.addWidget(movie1_link)
        vbox1.addStretch()

        hbox = QHBoxLayout(self.tab1)                              # + self.tab1
        hbox.addLayout(vbox1)
        hbox.addStretch()

#        self.setLayout(hbox)                                       # ---

    def tab2UI(self):
        pass

    def tab3UI(self):
        pass

    def tab4UI(self):
        pass


app = QApplication(sys.argv)
filmler = Filmler()
sys.exit(app.exec_())