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. Appending Qtablewidget row contents to qLineEdits
Forum Updated to NodeBB v4.3 + New Features

Appending Qtablewidget row contents to qLineEdits

Scheduled Pinned Locked Moved Unsolved General and Desktop
27 Posts 2 Posters 3.6k 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.
  • mrjjM mrjj

    Hi
    As i shown higher up.

    rows = {index.row() for index in self.tab.selectionModel().selectedIndexes()}
                lines = []
                itemList = []
                itemList.append(self.itemcodetabtx)
                itemList.append(self.itemnametx)
                itemList.append(self.comtabtx)
                itemList.append(self.modifiertabtx)
                itemList.append(self.modeltabtx)
                itemList.append(self.partntabtx)
    
                itemList.append(self.sizetabtx)
                itemList.append(self.matltabtx)
                itemList.append(self.rattabtx)
                itemList.append(self.mfrtabtx)
                itemList.append(self.additx)
                itemList.append(self.usertabtx)
    
                for row in rows:
                    texts = []
                    for j in range(self.tab.columnCount()):
                        itemcodd = self.tab.item(row, 0)
                        text = "" if itemcodd is None else itemcodd.text()
                       self.itemList[j].setText(text) // set the text to line edit via the list.
    
    C Offline
    C Offline
    CEO.
    wrote on last edited by CEO.
    #16

    @mrjj ohhhkay!!
    I just studied this again and I got your point. I understand it now. It works fine now.

    It works fine now.
    Do I have to be repeating the 'for loop' statement for the other columns?
    Lest I forget, I am very grateful for you attention.

    for row in rows:
                    #texts = []
                    for j in range(self.tab.columnCount()):
                        itemcodd = self.tab.item(row, 0)
                        text = "" if itemcodd is None else itemcodd.text()
                itemList[0].setText(text)
    
    mrjjM 1 Reply Last reply
    0
    • C CEO.

      @mrjj ohhhkay!!
      I just studied this again and I got your point. I understand it now. It works fine now.

      It works fine now.
      Do I have to be repeating the 'for loop' statement for the other columns?
      Lest I forget, I am very grateful for you attention.

      for row in rows:
                      #texts = []
                      for j in range(self.tab.columnCount()):
                          itemcodd = self.tab.item(row, 0)
                          text = "" if itemcodd is None else itemcodd.text()
                  itemList[0].setText(text)
      
      mrjjM Offline
      mrjjM Offline
      mrjj
      Lifetime Qt Champion
      wrote on last edited by mrjj
      #17

      Hi
      Ok super. Was afraid I didn't explain good enough.

      Well in my book the
      for j in range(self.itemList.columnCount()):
      should loop all coloums for the selected Row.

      Do notice that code won't do right if you select multiple rows but I assume that was not the plan.

      You are very welcome. Disclaimer. I suck at python as such but programming is programming and
      same tactics works regardless of language used-

      Whoops
      Just saw
      itemList[0].setText(text)
      should be
      itemList[j].setText(text)

      so we take next index when we take next col.

      I assume j will go 0,1,2,3,4 etc ?

      also when you take the text
      itemcodd = self.tab.item(row, 0)
      should that not be itemcodd = self.tab.item(row, j)
      so we take cols one by one and not just 0 (zero)

      C 1 Reply Last reply
      0
      • mrjjM mrjj

        @CEO
        What we try is to have a list of the edits so ew don't have to use names. else you have to do
        som ifs to make them go into the right line edits.

          for j in range(self.tab.columnCount()):
                            itemcodd = self.tab.item(row, j)
                            text = "" if itemcodd is None else itemcodd.text() 
                            if (j ==0 )
                            self.itemcodetabtx.setText(text)  
                            if (j ==1 )
                            self.itemcodeSOMEOTHERNAME.setText(text)  
         ....
        
        • Is there any difference between self.itemcodetabx.setText(output) and self.itemList[0].setText(output)?

        No. not really as in both cases we use a pointer to talk to the Lieedit but with LIST we
        can do it via index (j) and not name so its easier as else you must use if statements to star it in to the right edit . the one that matches the current column.

        C Offline
        C Offline
        CEO.
        wrote on last edited by
        #18

        @mrjj said in Appending Qtablewidget row contents to qLineEdits:

        @CEO
        What we try is to have a list of the edits so ew don't have to use names. else you have to do
        som ifs to make them go into the right line edits.

          for j in range(self.tab.columnCount()):
                            itemcodd = self.tab.item(row, j)
                            text = "" if itemcodd is None else itemcodd.text() 
                            if (j ==0 )
                            self.itemcodetabtx.setText(text)  
                            if (j ==1 )
                            self.itemcodeSOMEOTHERNAME.setText(text)  
         ....
        
        • Is there any difference between self.itemcodetabx.setText(output) and self.itemList[0].setText(output)?

        No. not really as in both cases we use a pointer to talk to the Lieedit but with LIST we
        can do it via index (j) and not name so its easier as else you must use if statements to star it in to the right edit . the one that matches the current column.

        This answers my most previous question. I like this format. Thanks a bunch.

        mrjjM 1 Reply Last reply
        0
        • C CEO.

          @mrjj said in Appending Qtablewidget row contents to qLineEdits:

          @CEO
          What we try is to have a list of the edits so ew don't have to use names. else you have to do
          som ifs to make them go into the right line edits.

            for j in range(self.tab.columnCount()):
                              itemcodd = self.tab.item(row, j)
                              text = "" if itemcodd is None else itemcodd.text() 
                              if (j ==0 )
                              self.itemcodetabtx.setText(text)  
                              if (j ==1 )
                              self.itemcodeSOMEOTHERNAME.setText(text)  
           ....
          
          • Is there any difference between self.itemcodetabx.setText(output) and self.itemList[0].setText(output)?

          No. not really as in both cases we use a pointer to talk to the Lieedit but with LIST we
          can do it via index (j) and not name so its easier as else you must use if statements to star it in to the right edit . the one that matches the current column.

          This answers my most previous question. I like this format. Thanks a bunch.

          mrjjM Offline
          mrjjM Offline
          mrjj
          Lifetime Qt Champion
          wrote on last edited by
          #19

          @CEO
          Ok. using ifs are also fine. :)

          C 1 Reply Last reply
          0
          • mrjjM mrjj

            @CEO
            Ok. using ifs are also fine. :)

            C Offline
            C Offline
            CEO.
            wrote on last edited by
            #20

            @mrjj updateTabbb.JPG

            aim accomplished. ALL THANKS to you. Honestly if you had directed me to QT documentation, I wouldn't have been able to understand it. I appreciate.

            mrjjM C 2 Replies Last reply
            0
            • C CEO.

              @mrjj updateTabbb.JPG

              aim accomplished. ALL THANKS to you. Honestly if you had directed me to QT documentation, I wouldn't have been able to understand it. I appreciate.

              mrjjM Offline
              mrjjM Offline
              mrjj
              Lifetime Qt Champion
              wrote on last edited by
              #21

              @CEO
              Np. Glad you could make it work.

              If you ever need to make something like this again, You can get most of it for free/no code
              if you use a standalone model as then you can also connect the LineEdits to the model with the table and it would auto sync.

              1 Reply Last reply
              0
              • C CEO.

                @mrjj updateTabbb.JPG

                aim accomplished. ALL THANKS to you. Honestly if you had directed me to QT documentation, I wouldn't have been able to understand it. I appreciate.

                C Offline
                C Offline
                CEO.
                wrote on last edited by
                #22

                @CEO alright. I am grateful.

                I have been thinking of ways I can design the table lines. is it possible please? For now, I can only setStylesheet to the table background. Is there anyway I can thicken the table lines and maybe give it another color different from the table background?

                mrjjM 1 Reply Last reply
                0
                • C CEO.

                  @CEO alright. I am grateful.

                  I have been thinking of ways I can design the table lines. is it possible please? For now, I can only setStylesheet to the table background. Is there anyway I can thicken the table lines and maybe give it another color different from the table background?

                  mrjjM Offline
                  mrjjM Offline
                  mrjj
                  Lifetime Qt Champion
                  wrote on last edited by
                  #23

                  @CEO
                  Well there is
                  https://doc.qt.io/qt-5/qtableview.html#gridStyle-prop
                  that allows you to set pen and color when drawing the grid.

                  Its also avialable for TableWidget as it inherits qtableview

                  C 3 Replies Last reply
                  1
                  • mrjjM mrjj

                    @CEO
                    Well there is
                    https://doc.qt.io/qt-5/qtableview.html#gridStyle-prop
                    that allows you to set pen and color when drawing the grid.

                    Its also avialable for TableWidget as it inherits qtableview

                    C Offline
                    C Offline
                    CEO.
                    wrote on last edited by
                    #24

                    @mrjj alright. thanks.
                    Let me check it out.

                    1 Reply Last reply
                    0
                    • mrjjM mrjj

                      @CEO
                      Well there is
                      https://doc.qt.io/qt-5/qtableview.html#gridStyle-prop
                      that allows you to set pen and color when drawing the grid.

                      Its also avialable for TableWidget as it inherits qtableview

                      C Offline
                      C Offline
                      CEO.
                      wrote on last edited by
                      #25

                      @mrjj I have studied the content. Honestly I hate reading QT documentations because they don't teach an individual how to use them. No illustrative example. Most things I know today, I learned from other links.
                      I have practicalized self.tab.setGrid() I don't know options to use. No much work on QT online and learning through the documentation is terrible.

                      1 Reply Last reply
                      0
                      • mrjjM mrjj

                        @CEO
                        Well there is
                        https://doc.qt.io/qt-5/qtableview.html#gridStyle-prop
                        that allows you to set pen and color when drawing the grid.

                        Its also avialable for TableWidget as it inherits qtableview

                        C Offline
                        C Offline
                        CEO.
                        wrote on last edited by
                        #26

                        @mrjj I found a better site to learn more about Qtablewidget. >>>>> https://topic.alibabacloud.com/a/use-of-qlistwidget-and-qtablewidget-and-style-settings_8_8_10259690.html

                        I hate Qt documentation site. They make it difficult for a beginner to understand

                        1 Reply Last reply
                        0
                        • mrjjM mrjj

                          Hi
                          Ok super. Was afraid I didn't explain good enough.

                          Well in my book the
                          for j in range(self.itemList.columnCount()):
                          should loop all coloums for the selected Row.

                          Do notice that code won't do right if you select multiple rows but I assume that was not the plan.

                          You are very welcome. Disclaimer. I suck at python as such but programming is programming and
                          same tactics works regardless of language used-

                          Whoops
                          Just saw
                          itemList[0].setText(text)
                          should be
                          itemList[j].setText(text)

                          so we take next index when we take next col.

                          I assume j will go 0,1,2,3,4 etc ?

                          also when you take the text
                          itemcodd = self.tab.item(row, 0)
                          should that not be itemcodd = self.tab.item(row, j)
                          so we take cols one by one and not just 0 (zero)

                          C Offline
                          C Offline
                          CEO.
                          wrote on last edited by
                          #27

                          @mrjj hello Mr. JJ, I am having challenge retrieving data into a qTablewidget. I have been retrieving data into qtablewidget before.

                          I used qtable in storing the data into the database and one of the columns in the table used qcombobox. Is it that I will have to retrieve that data into a qcombobox too?

                          I am asking this because I'm not seeing any error in my retrieval code.

                          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