Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. QML and Qt Quick
  4. Problem with selecting next/previowus record
Forum Updated to NodeBB v4.3 + New Features

Problem with selecting next/previowus record

Scheduled Pinned Locked Moved Unsolved QML and Qt Quick
16 Posts 3 Posters 814 Views 1 Watching
  • 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.
  • SGaistS SGaist

    Hi,

    Do you mean the else clause where you would use what is an invalid index ?

    Karoluss96K Offline
    Karoluss96K Offline
    Karoluss96
    wrote on last edited by
    #3

    @SGaist else for me is for situation when none of records in Table View is choosen ex. a little after pressing the button which shows the result of sql hidden in button

    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #4

      Can you provide a minimal script that shows the behavior ?
      It's not exactly clear from your description.

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      Karoluss96K 1 Reply Last reply
      0
      • Karoluss96K Offline
        Karoluss96K Offline
        Karoluss96
        wrote on last edited by
        #5

        I attached the whole of the code of this funtion above, I don't know what more can I add here

        1 Reply Last reply
        0
        • SGaistS SGaist

          Can you provide a minimal script that shows the behavior ?
          It's not exactly clear from your description.

          Karoluss96K Offline
          Karoluss96K Offline
          Karoluss96
          wrote on last edited by
          #6

          @SGaist ! I put a photo with a situation was that funtion does make:
          (na forum.PNG )

          1 Reply Last reply
          0
          • Karoluss96K Offline
            Karoluss96K Offline
            Karoluss96
            wrote on last edited by
            #7

            Please don't publish it in any media!

            1 Reply Last reply
            0
            • SGaistS Offline
              SGaistS Offline
              SGaist
              Lifetime Qt Champion
              wrote on last edited by
              #8

              That is why I was requesting a minimal runnable script to that would show your issue.

              From the looks of it, you can use QTableView's currentIndex to grab the currently selected index.

              From a code point of view, you should refactor your NextOne function. It's hard to read and reason about because you are not using meaningful variable names. Also, NextOne does not follow python best practices for function naming.

              Here a simplified and clearer version:

              def select_next_row(self):
                  selection_model = self.dlg.tableView_3.selectionModel()
                  current_index = selection_model.currentIndex()
                  if current_index.isValid():
                        next_index = current_index.siblingAtRow(current_index.row() + 1)
                        if next_index.isValid():
                            selection_model.select(next_index, QItemSelectionModel.ClearAndSelect | QItemSelectionModel.Rows)
              

              Unless you want to implement wrapping from the bottom to the top of your table view, there's nothing more that method should do.

              Interested in AI ? www.idiap.ch
              Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

              1 Reply Last reply
              0
              • Karoluss96K Offline
                Karoluss96K Offline
                Karoluss96
                wrote on last edited by
                #9

                Thnaks, but still change only to first next.
                What kind of code (for which funtion) you want to see to find better solution for my problem?

                jsulmJ 1 Reply Last reply
                0
                • Karoluss96K Karoluss96

                  Thnaks, but still change only to first next.
                  What kind of code (for which funtion) you want to see to find better solution for my problem?

                  jsulmJ Online
                  jsulmJ Online
                  jsulm
                  Lifetime Qt Champion
                  wrote on last edited by
                  #10

                  @Karoluss96 said in Problem with selecting next/previowus record:

                  What kind of code

                  A runnable script as small as possible which shows this behaviour.

                  https://forum.qt.io/topic/113070/qt-code-of-conduct

                  1 Reply Last reply
                  0
                  • Karoluss96K Offline
                    Karoluss96K Offline
                    Karoluss96
                    wrote on last edited by
                    #11

                    Function for showing records in tableView looks that:

                     def present_data(self):
                                query = QSqlQuery(db)
                                query.exec_(Zap)
                                global ier
                                ier= ['ID','TERYT'] #and more atributtes
                                self.model4.clear()
                                self.model4.setHorizontalHeaderLabels(ier)
                                x = 0
                                while query.next():
                                    x += 1
                                    self.model4.setItem(x, 0, QStandardItem(str(int(query.record().value(ier[0])))))#ID
                                    self.model4.setItem(x, 1, QStandardItem(str(query.record().value(ier[1]))))#code of ad level 1
                    #next atributtes in table 'ier'
                     self.dlg.tableView_3.clicked.connect(self.SelekcjaRzedu)
                    

                    and next:

                    def selectRow(self):
                                    dane=self.dlg.tableView_3.selectionModel().currentIndex()
                                    rzad=dane.row()
                                    self.dlg.label_53.setText(str(self.dlg.comboBox_9.currentText()))#administrative level 2 
                                    woj= ((self.dlg.comboBox_3.currentText())[0:-5]).lower()#administrative level 1 
                                    a1=dane.siblingAtRow(rzad).siblingAtColumn(0).data()#ID
                                    b2=dane.siblingAtRow(rzad).siblingAtColumn(1).data()#code of ad level 1
                    #next attributes...
                    if woj !='do':#not put NULL in labels
                                        self.dlg.label_82.setText(woj)
                                    else:
                                        self.dlg.label_82.setText('')
                                    if a1 != 'NULL':
                                        self.dlg.label_32.setText(str(a1))
                                    else:
                                        self.dlg.label_32.setText('')
                    
                    jsulmJ 1 Reply Last reply
                    0
                    • Karoluss96K Karoluss96

                      Function for showing records in tableView looks that:

                       def present_data(self):
                                  query = QSqlQuery(db)
                                  query.exec_(Zap)
                                  global ier
                                  ier= ['ID','TERYT'] #and more atributtes
                                  self.model4.clear()
                                  self.model4.setHorizontalHeaderLabels(ier)
                                  x = 0
                                  while query.next():
                                      x += 1
                                      self.model4.setItem(x, 0, QStandardItem(str(int(query.record().value(ier[0])))))#ID
                                      self.model4.setItem(x, 1, QStandardItem(str(query.record().value(ier[1]))))#code of ad level 1
                      #next atributtes in table 'ier'
                       self.dlg.tableView_3.clicked.connect(self.SelekcjaRzedu)
                      

                      and next:

                      def selectRow(self):
                                      dane=self.dlg.tableView_3.selectionModel().currentIndex()
                                      rzad=dane.row()
                                      self.dlg.label_53.setText(str(self.dlg.comboBox_9.currentText()))#administrative level 2 
                                      woj= ((self.dlg.comboBox_3.currentText())[0:-5]).lower()#administrative level 1 
                                      a1=dane.siblingAtRow(rzad).siblingAtColumn(0).data()#ID
                                      b2=dane.siblingAtRow(rzad).siblingAtColumn(1).data()#code of ad level 1
                      #next attributes...
                      if woj !='do':#not put NULL in labels
                                          self.dlg.label_82.setText(woj)
                                      else:
                                          self.dlg.label_82.setText('')
                                      if a1 != 'NULL':
                                          self.dlg.label_32.setText(str(a1))
                                      else:
                                          self.dlg.label_32.setText('')
                      
                      jsulmJ Online
                      jsulmJ Online
                      jsulm
                      Lifetime Qt Champion
                      wrote on last edited by
                      #12

                      @Karoluss96 This is not a RUNNABLE script...

                      https://forum.qt.io/topic/113070/qt-code-of-conduct

                      1 Reply Last reply
                      0
                      • Karoluss96K Offline
                        Karoluss96K Offline
                        Karoluss96
                        wrote on last edited by
                        #13

                        you want the run function?

                        1 Reply Last reply
                        0
                        • Karoluss96K Offline
                          Karoluss96K Offline
                          Karoluss96
                          wrote on last edited by
                          #14

                          the run function to open this gui looks that:

                          def run(self):
                          global TERYT, qmlPath, mainPath, controlPath, db, connectionParam, schema, password, database, port, host, oznaczenieZmiany

                              # paths to files
                              qmlPath = Path(QgsApplication.qgisSettingsDirPath())/Path("python/plugins/SystemBDOT10k/BDOT10k_QML/")
                              mainPath = Path(QgsApplication.qgisSettingsDirPath())/Path("python/plugins/SystemBDOT10k/")
                              controlPath = Path(QgsApplication.qgisSettingsDirPath())/Path("python/plugins/SystemBDOT10k/Kontrole/")
                              
                              self.dlg = SystemBDOT10k_dialog()
                              self.dlg.setWindowFlag(Qt.WindowMinimizeButtonHint, True)
                              self.dlg.rejected.connect(self.close)
                              
                              #get parameters from file SystemBDOT10k.ini 
                              config = configparser.ConfigParser()
                              config.read(str(mainPath)+'/SystemBDOT10k.ini')
                              connectionParam = config['oracle']
                              schema = (base64.b64decode((connectionParam['Schema']).encode('utf-8'))).decode('utf-8')
                              password = (base64.b64decode((connectionParam['Password']).encode('utf-8'))).decode('utf-8')
                              port = connectionParam['Port']
                              host = connectionParam['Host']
                              database = connectionParam['Database']
                              markChange = config['MainSettings']['markChange']
                          
                              # connect to data base
                              db = QSqlDatabase.addDatabase("QOCISPATIAL")
                              db.setDatabaseName(host + ':' + port + '/' + database)
                              db.setUserName(schema)
                              db.setPassword(password)
                              ok = db.open()
                              self.operetionOnData()
                              
                              
                              self.dlg.comboBox.currentTextChanged.connect(self.chooseStatus)
                              
                              self.statusPowiatu()
                              self.chooseStatus()
                              
                              # selecting QML folders to comboBox
                              path = os.listdir(str(qmlPath).replace("\\","/"))
                              length = len(path)
                              for i in range(length):
                                  self.dlg.comboBox_1.addItem(path[i])
                                  
                              self.dlg.show() 
                              result = self.dlg.exec_() # Run the dialog event loop
                          
                          jsulmJ 1 Reply Last reply
                          0
                          • Karoluss96K Karoluss96

                            the run function to open this gui looks that:

                            def run(self):
                            global TERYT, qmlPath, mainPath, controlPath, db, connectionParam, schema, password, database, port, host, oznaczenieZmiany

                                # paths to files
                                qmlPath = Path(QgsApplication.qgisSettingsDirPath())/Path("python/plugins/SystemBDOT10k/BDOT10k_QML/")
                                mainPath = Path(QgsApplication.qgisSettingsDirPath())/Path("python/plugins/SystemBDOT10k/")
                                controlPath = Path(QgsApplication.qgisSettingsDirPath())/Path("python/plugins/SystemBDOT10k/Kontrole/")
                                
                                self.dlg = SystemBDOT10k_dialog()
                                self.dlg.setWindowFlag(Qt.WindowMinimizeButtonHint, True)
                                self.dlg.rejected.connect(self.close)
                                
                                #get parameters from file SystemBDOT10k.ini 
                                config = configparser.ConfigParser()
                                config.read(str(mainPath)+'/SystemBDOT10k.ini')
                                connectionParam = config['oracle']
                                schema = (base64.b64decode((connectionParam['Schema']).encode('utf-8'))).decode('utf-8')
                                password = (base64.b64decode((connectionParam['Password']).encode('utf-8'))).decode('utf-8')
                                port = connectionParam['Port']
                                host = connectionParam['Host']
                                database = connectionParam['Database']
                                markChange = config['MainSettings']['markChange']
                            
                                # connect to data base
                                db = QSqlDatabase.addDatabase("QOCISPATIAL")
                                db.setDatabaseName(host + ':' + port + '/' + database)
                                db.setUserName(schema)
                                db.setPassword(password)
                                ok = db.open()
                                self.operetionOnData()
                                
                                
                                self.dlg.comboBox.currentTextChanged.connect(self.chooseStatus)
                                
                                self.statusPowiatu()
                                self.chooseStatus()
                                
                                # selecting QML folders to comboBox
                                path = os.listdir(str(qmlPath).replace("\\","/"))
                                length = len(path)
                                for i in range(length):
                                    self.dlg.comboBox_1.addItem(path[i])
                                    
                                self.dlg.show() 
                                result = self.dlg.exec_() # Run the dialog event loop
                            
                            jsulmJ Online
                            jsulmJ Online
                            jsulm
                            Lifetime Qt Champion
                            wrote on last edited by
                            #15

                            @Karoluss96 Runnable means in this case: something somebody can download/copy from here and drectly execute to reproduce your issue.

                            https://forum.qt.io/topic/113070/qt-code-of-conduct

                            1 Reply Last reply
                            0
                            • Karoluss96K Offline
                              Karoluss96K Offline
                              Karoluss96
                              wrote on last edited by
                              #16

                              This is a QGIS plugin with GUI, so it isn't possible to put it outside of QGIS program (which you can download for free here: https://qgis.org/pl/site/forusers/download.html)

                              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