QTabWidget类的继承层次结构如下:
(QObject, QPaintDevice) - QWidget - QTabWidget
QTabWidget类的构造函数为:
QTabWidget([QWidget parent])
以下是显示上图的代码:
from PyQt5 import QtWidgets
import sys
app = QtWidgets.QApplication (sys.argv)
window = QtWidgets.QWidget ()
window.setWindowTitle ("QTabWidget")
window.resize (400, 100)
tab = QtWidgets.QTabWidget ()
tab.addTab (QtWidgets.QLabel ("Tab Content 1"), "Tab & 1")
tab.addTab (QtWidgets.QLabel ("Tab Content 2"), "Tab & 2")
tab.addTab (QtWidgets.QLabel ("Tab Content 3"), "Tab & 3")
tab.setCurrentIndex (0)
vbox = QtWidgets.QVBoxLayout ()
vbox.addWidget (tab)
window.setLayout (vbox)
window.show ()
sys.exit (app.exec_ ())