我正在努力在我的 GUI 中正确布局选项卡。如您所见,拆分器右侧的 QFrame 未跨越整个窗口 - 我怀疑这是因为它没有添加到任何跨越整个选项卡的布局中,但我无法弄清楚如何做到这一点,并且花了一段时间才弄明白。有人能帮帮我吗?
from PyQt5.QtWidgets import QApplication, QMainWindow, QWidget, QVBoxLayout, QSplitter, QTabWidget, QPlainTextEdit, \
QHBoxLayout, QFrame, QTableWidget
from PyQt5.QtGui import QCloseEvent
from PyQt5.QtCore import Qt
import sys
class MainWindow(QMainWindow):
def __init__(self, parent=None):
super().__init__(parent)
self.setWindowTitle('title')
self.resize(1400, 800)
central_widget = QWidget()
self.setCentralWidget(central_widget)
main_layout = QVBoxLayout(central_widget)
splitter = QSplitter()
main_layout.addWidget(splitter)
# Left tabs for plots
left_tab_widget = QTabWidget()
self.left_tab_1 = QWidget()
self.left_tab_2 = QWidget()
self.left_tab_3 = QWidget()
left_tab_widget.addTab(self.left_tab_1, "left 1")
left_tab_widget.addTab(self.left_tab_2, "left 2")
left_tab_widget.addTab(self.left_tab_3, "left 3")
# Right tabs for GUI
# main tabs
right_tab_widget = QTabWidget()
self.right_tab_1 = QWidget()
self.right_tab_2 = QWidget()
# child tabs
right_tab_2_children = QTabWidget()
self.right_tab_2_1 = QWidget()
self.right_tab_2_2 = StructureVariableControls()
right_tab_2_children.addTab(self.right_tab_2_1, "right 2_1")
right_tab_2_children.addTab(self.right_tab_2_2, "right 2_2")
right_tab_widget.addTab(self.right_tab_1, "right 1")
right_tab_widget.addTab(right_tab_2_children, "right 2")
splitter.addWidget(left_tab_widget)
splitter.addWidget(right_tab_widget)
right_tab_widget.setCurrentIndex(1)
right_tab_2_children.setCurrentIndex(1)
class StructureVariableControls(QWidget):
def __init__(self):
super().__init__()
self.layout = QVBoxLayout()
self.layout.setAlignment(Qt.AlignTop)
self.frame = QFrame(self)
self.frame.setFrameShape(QFrame.StyledPanel)
self.frame.setFrameShadow(QFrame.Raised)
self.frame.setStyleSheet("background-color: rgb(200, 200, 200);")
self.frame.setLineWidth(10)
self.frame_layout = QVBoxLayout(self.frame)
self.table_widget = QTableWidget()
self.frame_layout.addWidget(self.table_widget)
if __name__ == '__main__':
app = QApplication(sys.argv)
window = MainWindow()
window.show()
sys.exit(app.exec_())