<>QTabWidget

common method

Method description
addTab() Add a control to the Tab Control
insertTab() Will be a Tab Control to the specified location
removeTab() Delete according to the specified index Tab control
setCurrentIndex() Sets the index of the currently visible tab
setCurrentWidget() Set the currently visible interface
setTabBar() Set tab bar gizmos
setTabPosition() Set the location of the tab
-QTabWidget.North: Displayed at the top of the page
-QTabWidget.South: Displayed at the bottom of the page
-QTabWidget.West: Displayed on the left side of the page
-- QTabWidget.East: Displayed on the right side of the page
setTabText() definition Tab The display value of the tab
Common signals

Signal description
currentChanged This signal is transmitted when the current page is switched import sys from PyQt5.QtCore import * from PyQt5.
QtGuiimport * from PyQt5.QtWidgets import * class TabDemo(QTabWidget): def
__init__(self, parent=None): super(TabDemo, self).__init__(parent) self.tab1 =
QWidget() self.tab2 = QWidget() self.tab3 = QWidget() self.addTab(self.tab1,
"Tab 1") self.addTab(self.tab2,"Tab 2") self.addTab(self.tab3,"Tab 3") self.
tab1UI() self.tab2UI() self.tab3UI() self.setWindowTitle("Tab example ") def tab1UI(
self): layout = QFormLayout() layout.addRow(" full name ",QLineEdit()) layout.addRow(" address "
,QLineEdit()) self.setTabText(0," contact information ") self.tab1.setLayout(layout) def tab2UI(
self): layout = QFormLayout() sex = QHBoxLayout() sex.addWidget(QRadioButton(" male "
)) sex.addWidget(QRadioButton(" female ")) layout.addRow(QLabel(" Gender "),sex) layout.
addRow(" birthday ",QLineEdit()) self.setTabText(1," Personal details ") self.tab2.setLayout(layout)
def tab3UI(self): layout=QHBoxLayout() layout.addWidget(QLabel(" subject ")) layout.
addWidget(QCheckBox(" Physics ")) layout.addWidget(QCheckBox(" High number ")) self.setTabText(2,
" Education level ") self.tab3.setLayout(layout) if __name__ == '__main__': app =
QApplication(sys.argv) demo = TabDemo() demo.show() sys.exit(app.exec_())
In this case , The content of a form is divided into 3 group , Each set of widgets is displayed in a different tab , The top window is a QTabWidget control , Add three tabs
# establish 3 Tab widget window self.tab1=QWidget() self.tab2=QWidget() self.tab3=QWidget()
# Add three tabs to the top-level window self.addTab(self.tab1, "Tab 1") self.addTab(self.tab2, "Tab 2")
self.addTab(self.tab3, "Tab 3")
Using the form layout manager , Each tab displays the contents of the subform
self.setTabText(0,' contact information ') self.setTabText(
<>QStackedWidget

QTackedWidget Is a stack window control , You can fill in some small controls , However, only one small control can be displayed at the same time ,QStackedWidget use QStackedLayout layout .QSTackedWidget Controls and QTabWidget similar , Can effectively display the window control
import sys from PyQt5.QtGui import * from PyQt5.QtCore import * from PyQt5.
QtWidgetsimport * class StackedExample(QWidget): def __init__(self): super(
StackedExample, self).__init__() # Set the initial position and size of the window self.setGeometry(300,50,10,10)
self.setWindowTitle('StackedWidget example ') # Create list window , add entry self.leftlist=QListWidget()
self.leftlist.insertItem(0,' contact information ') self.leftlist.insertItem(1,' personal information ') self.
leftlist.insertItem(2,' Education level ') # Create three small controls self.stack1=QWidget() self.stack2=QWidget
() self.stack3=QWidget() self.stack1UI() self.stack2UI() self.stack3UI()
# stay QStackedWidget Object is populated with three child controls self.stack=QStackedWidget(self) self.stack.addWidget
(self.stack1) self.stack.addWidget(self.stack2) self.stack.addWidget(self.stack3
) # Horizontal layout , Add parts to layout HBox=QHBoxLayout() HBox.addWidget(self.leftlist) HBox.addWidget
(self.stack) self.setLayout(HBox) self.leftlist.currentRowChanged.connect(self.
display) def stack1UI(self): layout=QFormLayout() layout.addRow(' full name ',QLineEdit()
) layout.addRow(' address ',QLineEdit()) self.stack1.setLayout(layout) def stack2UI(
self): # zhu Table Layout , Sub level layout layout = QFormLayout() sex = QHBoxLayout() # Horizontal layout add radio button
sex.addWidget(QRadioButton(' male ')) sex.addWidget(QRadioButton(' female ')) # Form layout add control
layout.addRow(QLabel(' Gender '), sex) layout.addRow(' birthday ', QLineEdit()) self.stack2.
setLayout(layout) def stack3UI(self): # Horizontal layout layout = QHBoxLayout() # Add control to layout
layout.addWidget(QLabel(' subject ')) layout.addWidget(QCheckBox(' Physics ')) layout.
addWidget(QCheckBox(' High number ')) self.stack3.setLayout(layout) def display(self,i):
# Sets the index of the currently visible tab self.stack.setCurrentIndex(i) if __name__ == '__main__': app=
QApplication(sys.argv) demo=StackedExample() demo.show() sys.exit(app.exec_())
In this case , stay QStackedWidget Object is populated with three child controls
self.stack1=QWidget() self.stack2=QWidget() self.stack3=QWidget()
# stay QStackedWidget Object is populated with three child controls self.stack=QStackedWidget(self)
self.stack.addWidget(self.stack1) self.stack.addWidget(self.stack2)
self.stack.addWidget(self.stack3)

Each child control can have its own layout , Contains specific form elements ,QStackedWidget Control cannot switch between pages , It is the same as the currently selected QListWidget Control
# Create list window , add entry self.leftlist=QListWidget() self.leftlist.insertItem(0,' contact information ')
self.leftlist.insertItem(1,' personal information ') self.leftlist.insertItem(2,' Education level ')
self.leftlist.currentRowChanged.connect(self.display)
take QListWidget Of currentRowChanged Signals and display() Slot function , This changes the view of the stack control
def display(self,i): # Sets the index of the currently visible tab self.stack.setCurrentIndex(i)
<>QDockWidget

common method

import sys from PyQt5.QtCore import * from PyQt5.QtGui import * from PyQt5.
QtWidgetsimport * class DockDemo(QMainWindow): def __init__(self,parent=None):
super(DockDemo, self).__init__(parent) # Set horizontal layout layout=QHBoxLayout() # Instantiate menu bar bar=
self.menuBar() # Create main menu file, Add a submenu to it file=bar.addMenu('File') file.addAction('New'
) file.addAction('Save') file.addAction('quit') # establish QDockWidget window ( title , Self window ) self.
items=QDockWidget('Dockable',self) # Instantiate list window , Add a few entries self.listWidget=QListWidget()
self.listWidget.addItem('Item1') self.listWidget.addItem('Item2') self.
listWidget.addItem('Item3') self.listWidget.addItem('Item4')
# Set in window area QWidget, Add list control self.items.setWidget(self.listWidget)
# set up dock Can the window float ,True, Run floating outside , Automatically separated from the main interface ,False, Default floating in main window , It can be disengaged manually self.items.
setFloating(False) # set up QTextEdit Is the central widget self.setCentralWidget(QTextEdit())
# Place the window on the right side of the central widget self.addDockWidget(Qt.RightDockWidgetArea,self.items) self.
setLayout(layout) self.setWindowTitle('Dock example ') if __name__ == '__main__': app=
QApplication(sys.argv) demo=DockDemo() demo.show() sys.exit(app.exec_())
You can drag

In this case , The top window is a QMainWindow object ,QTextEdit Object is its central widget
self.setCentralWidget(QTextEdit())
First, create dockable windows Item
self.items=QDockWidget('Dockable',self)
then , Add in docking window QListWidget object
self.listWidget=QListWidget() self.listWidget.addItem('Item1')
self.listWidget.addItem('Item2') self.listWidget.addItem('Item3')
self.listWidget.addItem('Item4') # Set in window area QWidget, Add list control
self.items.setWidget(self.listWidget)
last , The docking window is placed on the right side of the central widget
self.addDockWidget(Qt.RightDockWidgetArea,self.items)

Computer innovation of electrical specialty , Blogging is not easy . If you think this article is useful to you , Please click like to support , thank you .

Technology
©2019-2020 Toolsou All rights reserved,
Huawei 2021 session Hardware Engineer Logical post (FPGA) Super detailed surface !!!Vue-element-admin upgrade ui edition virtual machine VMware Download and install the most detailed tutorial !C++ Move constructor and copy constructor sound of dripping water java Backstage interview pygame Realize full screen mode and adjustable window size mysql Database setting character set configuration modification my.ini file (windows)30 What's the experience of being a junior programmer at the age of 20 C++ Multithreading programming ( Summary of common functions and parameters )python_ cherry tree