Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. AttributeError: 'MainWindow' object has no attribute 'Region_comboBox'
Forum Updated to NodeBB v4.3 + New Features

AttributeError: 'MainWindow' object has no attribute 'Region_comboBox'

Scheduled Pinned Locked Moved Unsolved General and Desktop
4 Posts 3 Posters 3.6k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • L Offline
    L Offline
    LT-K101
    wrote on last edited by LT-K101
    #1

    I don't know what I'm doing wrong here. I have sat behind this the whole time trying to figure out this error. Please any assistance would help.Thanks

    class MainWindow(QtWidgets.QMainWindow):
    
        def __init__(self):
    
            super(MainWindow, self).__init__()
            self.ui = Ui_MainWindow()
            self.ui.setupUi(self)
    
            self.model = QtGui.QStandardItemModel()
    
            self.Region_comboBox.setModel(self.model)
            self.District_comboBox.setModel(self.model)
    
            data = {
                "A": ["a1", "a2"],
                "B": ["b1", "b2"],
                "C": ["c1", "c2"],
                "D": ["D1", "D2"]
            }
    
            # add data
            for k, v in data.items():
                region = QStandardItem()
                self.model.appendRow(region)
                for value in v:
                    district = QStandardItem()
                    region.append(district)
    
            self.Region_comboBox.currentIndexChanged.connect(self.updateRegionCombo)
            self.updateRegionCombo(0)
    
        def updateRegionCombo(self, index):
            indx = self.model.index(index, 0, self.Region_comboBox.rootModelIndex())
            self.District_comboBox.setRootModelIndex(indx)
            self.District_comboBox.setCurrentIndex(0)
    
    JonBJ eyllanescE 2 Replies Last reply
    0
    • L LT-K101

      I don't know what I'm doing wrong here. I have sat behind this the whole time trying to figure out this error. Please any assistance would help.Thanks

      class MainWindow(QtWidgets.QMainWindow):
      
          def __init__(self):
      
              super(MainWindow, self).__init__()
              self.ui = Ui_MainWindow()
              self.ui.setupUi(self)
      
              self.model = QtGui.QStandardItemModel()
      
              self.Region_comboBox.setModel(self.model)
              self.District_comboBox.setModel(self.model)
      
              data = {
                  "A": ["a1", "a2"],
                  "B": ["b1", "b2"],
                  "C": ["c1", "c2"],
                  "D": ["D1", "D2"]
              }
      
              # add data
              for k, v in data.items():
                  region = QStandardItem()
                  self.model.appendRow(region)
                  for value in v:
                      district = QStandardItem()
                      region.append(district)
      
              self.Region_comboBox.currentIndexChanged.connect(self.updateRegionCombo)
              self.updateRegionCombo(0)
      
          def updateRegionCombo(self, index):
              indx = self.model.index(index, 0, self.Region_comboBox.rootModelIndex())
              self.District_comboBox.setRootModelIndex(indx)
              self.District_comboBox.setCurrentIndex(0)
      
      JonBJ Offline
      JonBJ Offline
      JonB
      wrote on last edited by
      #2

      @LT-K101 said in AttributeError: 'MainWindow' object has no attribute 'Region_comboBox':

      self.Region_comboBox.setModel(self.model)

      Exactly what the error messages tells you. You have never set any self.Region_comboBox.

      1 Reply Last reply
      1
      • L LT-K101

        I don't know what I'm doing wrong here. I have sat behind this the whole time trying to figure out this error. Please any assistance would help.Thanks

        class MainWindow(QtWidgets.QMainWindow):
        
            def __init__(self):
        
                super(MainWindow, self).__init__()
                self.ui = Ui_MainWindow()
                self.ui.setupUi(self)
        
                self.model = QtGui.QStandardItemModel()
        
                self.Region_comboBox.setModel(self.model)
                self.District_comboBox.setModel(self.model)
        
                data = {
                    "A": ["a1", "a2"],
                    "B": ["b1", "b2"],
                    "C": ["c1", "c2"],
                    "D": ["D1", "D2"]
                }
        
                # add data
                for k, v in data.items():
                    region = QStandardItem()
                    self.model.appendRow(region)
                    for value in v:
                        district = QStandardItem()
                        region.append(district)
        
                self.Region_comboBox.currentIndexChanged.connect(self.updateRegionCombo)
                self.updateRegionCombo(0)
        
            def updateRegionCombo(self, index):
                indx = self.model.index(index, 0, self.Region_comboBox.rootModelIndex())
                self.District_comboBox.setRootModelIndex(indx)
                self.District_comboBox.setCurrentIndex(0)
        
        eyllanescE Offline
        eyllanescE Offline
        eyllanesc
        wrote on last edited by eyllanesc
        #3

        @LT-K101 Change self.Region_comboBox to self.ui.Region_comboBox, and self.District_comboBox to self.ui.District_comboBox.

        If you want me to help you develop some work then you can write to my email: e.yllanescucho@gmal.com.

        L 1 Reply Last reply
        1
        • eyllanescE eyllanesc

          @LT-K101 Change self.Region_comboBox to self.ui.Region_comboBox, and self.District_comboBox to self.ui.District_comboBox.

          L Offline
          L Offline
          LT-K101
          wrote on last edited by
          #4

          @eyllanesc Thanks a lot it worked perfectly

          1 Reply Last reply
          0

          • Login

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • Users
          • Groups
          • Search
          • Get Qt Extensions
          • Unsolved