The difference between the usage of Qstackedwidget and qstackedlayout

Source: Internet
Author: User





import sys
from PyQt5 import QtWidgets, QtCore


class MyWidget (QtWidgets.QWidget):
    def __init __ (self, i = 0):
        super () .__ init __ ()
        self.setWindowTitle (‘Window‘ + str (i))
        label = QtWidgets.QLabel (‘label‘ + 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) # ① corresponding to addWidget
        layout.addLayout (stack) # ② corresponds to addLayout

        for i in range (10):
            stack.addWidget (MyWidget (i))
            list.addItem ("window% 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_ ()) 





The difference between the usage of Qstackedwidget and qstackedlayout


Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.