zoukankan      html  css  js  c++  java
  • QStackedWidget 与 QStackedLayout 的用法区别

     

    import sys
    from PyQt5 import QtWidgets, QtCore
    
    
    class MyWidget(QtWidgets.QWidget):
        def __init__(self, i=0):
            super().__init__()
            self.setWindowTitle('窗口 ' + str(i))
            label = QtWidgets.QLabel('标签 ' + str(i))
            layout = QtWidgets.QHBoxLayout(self)
            layout.addWidget(label)
            
    
    class TestWidget(QtWidgets.QWidget):
        def __init__(self, parent=None):
            super().__init__(parent)
            
            layout = QtWidgets.QHBoxLayout(self)
            
            #stack  = QtWidgets.QStackedWidget() # ① Widget
            stack  = QtWidgets.QStackedLayout() # ② Layout
    
            list   = QtWidgets.QListWidget(self)
            list.setDragEnabled(True)
            list.setDragDropMode(QtWidgets.QAbstractItemView.InternalMove)
    
            layout.addWidget(list)
            #layout.addWidget(stack) # ① 对应 addWidget
            layout.addLayout(stack) # ② 对应 addLayout
    
            for i in range(10):
                stack.addWidget(MyWidget(i))
                list.addItem("窗口   %04i" % i)
    
            list.currentRowChanged.connect(stack.setCurrentIndex)
    
    
    if __name__ == "__main__":
        app    = QtWidgets.QApplication(sys.argv)
        widget = TestWidget()
        #widget = MyWidget()
        widget.show()
        sys.exit(app.exec_())
            # ... ...
    
            self.contentsWidget.currentItemChanged.connect(self.changePage)
            #self.contentsWidget.currentRowChanged.connect(self.pagesWidget.setCurrentIndex)
    
    
        def changePage(self, current, previous):
            if not current:
                current = previous
            self.pagesWidget.setCurrentIndex(self.contentsWidget.row(current))
  • 相关阅读:
    由于服务主机:DCOM服务进程占用过多CPU,导致系统卡死
    MySQL优化
    input type="file"文件上传到后台读取
    mysql 创建事件
    Quartz.Net实现的定时执行任务调度
    js 编码详解
    C# DateTime.Now 详解
    C# 读写text 详细讲解
    百度地图API详细介绍
    layui table 详细讲解
  • 原文地址:https://www.cnblogs.com/hhh5460/p/5191626.html
Copyright © 2011-2022 走看看