How do you get a class rim in MainWindow?



  • Got a class. FirstWindowwho inherits the class QMainWindow♪ There's also a class. FirstWigetwho inherits the class QGroupBox

    How to make a class object FirstWiget I'm on the open window of the class. FirstWindow?

    class FirstWindow(QtWidgets.QMainWindow):
        def __init__(self):
            super().__init__()
            self.initUI()
        def initUI(self):
            # какой то код код
            pass
    

    class FirstWiget(QtWidgets.QGroupBox):
    def init(self):
    super().init()
    self.initUI()
    def initUI(self):
    #какой то код код
    pass
    if name == 'main':
    app = QtWidgets.QApplication(sys.argv)
    w = FirstWiget()
    w.show()
    sys.exit(app.exec())



  • Try this:

    import sys
    from PyQt5.Qt import *
    from PyQt5 import QtCore, QtGui, QtWidgets
    

    class FirstWiget(QtWidgets.QGroupBox):
    def init(self):
    super().init()

        self.setTitle('FirstWiget') 
        self.setStyleSheet('''
            background-color: rgb(99, 125, 187); 
            border: 2px solid #ff2b3f;;
        ''')
        
        self.initUI()
        
    def initUI(self):
        #какой то код код
        pass
    

    class FirstWindow(QtWidgets.QMainWindow):
    def init(self):
    super().init()
    self.centralWidget = QWidget()
    self.setCentralWidget(self.centralWidget)
    self.setWindowTitle('FirstWindow')

        layout = QtWidgets.QGridLayout(self.centralWidget)        
        
        self.initUI()
        
        layout.addWidget(self.firstWiget)
        
    def initUI(self):
        # какой то код код
        self.firstWiget = FirstWiget()
    

    if name == 'main':
    app = QtWidgets.QApplication(sys.argv)
    w = FirstWindow()
    w.show()
    sys.exit(app.exec())

    введите сюда описание изображения



Suggested Topics

  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2