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. How to display QTableWidget selected row in a qLineEdit of the same class?
Forum Updated to NodeBB v4.3 + New Features

How to display QTableWidget selected row in a qLineEdit of the same class?

Scheduled Pinned Locked Moved Unsolved General and Desktop
pyqt5python3qtablewidgetsetfoc
12 Posts 3 Posters 4.1k 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.
  • S Offline
    S Offline
    SGaist
    Lifetime Qt Champion
    wrote on 4 Aug 2021, 18:53 last edited by
    #2

    Hi,

    Do you mean you want to build a string of the row and then put that in your QLineEdit ?

    For example in a slot connected to the currentCellChanged signal ?

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

    C 1 Reply Last reply 5 Aug 2021, 10:21
    2
    • C Offline
      C Offline
      CEO.
      wrote on 5 Aug 2021, 10:10 last edited by
      #3

      yes., I want the contents of the selected row displayed in the qLineEdit there

      1 Reply Last reply
      0
      • S SGaist
        4 Aug 2021, 18:53

        Hi,

        Do you mean you want to build a string of the row and then put that in your QLineEdit ?

        For example in a slot connected to the currentCellChanged signal ?

        C Offline
        C Offline
        CEO.
        wrote on 5 Aug 2021, 10:21 last edited by
        #4

        @SGaist thanks for your concern. I have fixed it. Now I wanna try to create different QLineEdits for each column and make the selected row display their corresponding values instead of in a single line edit.

        Have you tried such before please?

        J 1 Reply Last reply 5 Aug 2021, 10:38
        0
        • C CEO.
          5 Aug 2021, 10:21

          @SGaist thanks for your concern. I have fixed it. Now I wanna try to create different QLineEdits for each column and make the selected row display their corresponding values instead of in a single line edit.

          Have you tried such before please?

          J Offline
          J Offline
          JonB
          wrote on 5 Aug 2021, 10:38 last edited by
          #5

          @CEO
          You can do all this work yourself with your own line edits, but this is not the best/easiest/most efficient way to go. Instead Qt offers you two ways which (I think) are better:

          • You can make it so the QTableWidget is editable: the user clicks into a cell and edits it there. No separate line edits. If you like it that way.

          • You can use QDataWidgetMapper to "map" a whole series of separate, individual appropriate edit widgets to the columns in the selected row of a model. If you like it that way.

          C 1 Reply Last reply 5 Aug 2021, 10:51
          2
          • J JonB
            5 Aug 2021, 10:38

            @CEO
            You can do all this work yourself with your own line edits, but this is not the best/easiest/most efficient way to go. Instead Qt offers you two ways which (I think) are better:

            • You can make it so the QTableWidget is editable: the user clicks into a cell and edits it there. No separate line edits. If you like it that way.

            • You can use QDataWidgetMapper to "map" a whole series of separate, individual appropriate edit widgets to the columns in the selected row of a model. If you like it that way.

            C Offline
            C Offline
            CEO.
            wrote on 5 Aug 2021, 10:51 last edited by
            #6

            @JonB thanks. I want the displayed values in their corresponding and different line edits. Can you write a code for that plz?
            Just the function

            J 1 Reply Last reply 5 Aug 2021, 10:53
            0
            • C CEO.
              5 Aug 2021, 10:51

              @JonB thanks. I want the displayed values in their corresponding and different line edits. Can you write a code for that plz?
              Just the function

              J Offline
              J Offline
              JonB
              wrote on 5 Aug 2021, 10:53 last edited by
              #7

              @CEO said in How to display QTableWidget selected row in a qLineEdit of the same class?:

              Can you write a code for that plz?

              Are you serious?

              I want the displayed values in their corresponding and different line edits.

              Then I would suggest you use the QDataWidgetMapper.

              C 1 Reply Last reply 5 Aug 2021, 10:54
              0
              • J JonB
                5 Aug 2021, 10:53

                @CEO said in How to display QTableWidget selected row in a qLineEdit of the same class?:

                Can you write a code for that plz?

                Are you serious?

                I want the displayed values in their corresponding and different line edits.

                Then I would suggest you use the QDataWidgetMapper.

                C Offline
                C Offline
                CEO.
                wrote on 5 Aug 2021, 10:54 last edited by
                #8

                @JonB this doesn't answer my request plz

                J 1 Reply Last reply 5 Aug 2021, 10:55
                0
                • C CEO.
                  5 Aug 2021, 10:54

                  @JonB this doesn't answer my request plz

                  J Offline
                  J Offline
                  JonB
                  wrote on 5 Aug 2021, 10:55 last edited by
                  #9

                  @CEO
                  What doesn't answer your request? That I write your code for you to save you learning how to do it?

                  C 1 Reply Last reply 5 Aug 2021, 14:06
                  3
                  • C Offline
                    C Offline
                    CEO.
                    wrote on 5 Aug 2021, 13:35 last edited by
                    #10

                    is there anything wrong in writing a line of code to give someone a clue? I assist different people when lines of codes if I really know it and have done some works with it to guide them whenever I am suggesting an answer. It saves them from restlessness.

                    1 Reply Last reply
                    0
                    • J JonB
                      5 Aug 2021, 10:55

                      @CEO
                      What doesn't answer your request? That I write your code for you to save you learning how to do it?

                      C Offline
                      C Offline
                      CEO.
                      wrote on 5 Aug 2021, 14:06 last edited by
                      #11

                      @JonB now I discovered you are either hoarding knowledge or might not have done any work on the question. I checked different contributions in some thread now and saw some members explicitly writing out lines of codes. One of them even helped me greatly and I just have to call him a pro. If you know, there's no need hoarding it.

                      Anyway, thanks for the time.

                      J 1 Reply Last reply 6 Aug 2021, 07:04
                      0
                      • C CEO.
                        5 Aug 2021, 14:06

                        @JonB now I discovered you are either hoarding knowledge or might not have done any work on the question. I checked different contributions in some thread now and saw some members explicitly writing out lines of codes. One of them even helped me greatly and I just have to call him a pro. If you know, there's no need hoarding it.

                        Anyway, thanks for the time.

                        J Offline
                        J Offline
                        JonB
                        wrote on 6 Aug 2021, 07:04 last edited by JonB 8 Jun 2021, 07:05
                        #12

                        @CEO said in How to display QTableWidget selected row in a qLineEdit of the same class?:

                        @JonB now I discovered you are either hoarding knowledge or might not have done any work on the question.

                        Yes, you're right. I have nothing better to do than lie to questioners about what I know and they should do, and I don't spend enough of my time writing the code demanded to save them time.

                        Here is an extract from my usage of the QDataWidgetMapper which I know nothing about from a sample project of mine. I'm sorry if my variables/widgets/model are not the same as yours. Also here I happen to be binding to QSpinBoxes, let me know if I need to change it to QLineEdits for you.

                        void SectorRegisters::initDataWidgetMapper()
                        {
                            // set up the `QDataWidgetMapper`
                            this->dwm = new QDataWidgetMapper(this);
                            // set model (this->sectorsModel is the model being used, in my case it's a `QStandardItemModel`)
                            SectorsModel *sectorsModel = this->sectorsModel;
                            dwm->setModel(sectorsModel);
                            // Vertical => widget mapped to row
                            dwm->setOrientation(Qt::Vertical);
                            // current index is always column #0
                            dwm->setCurrentIndex(0);
                        
                            // Region mappings
                            dwm->addMapping(ui->spinRegionSocialState, SectorsModel::RegionSocialState);
                            dwm->addMapping(ui->spinRegionGoodAreas, SectorsModel::RegionGoodAreas);
                            dwm->addMapping(ui->spinRegionPoorAreas, SectorsModel::RegionPoorAreas);
                            dwm->addMapping(ui->spinRegionCash, SectorsModel::RegionCash);
                        
                            // Here there are many further widget<->model-column mappings
                            // ...
                        }
                        

                        You're welcome.

                        1 Reply Last reply
                        2

                        11/12

                        5 Aug 2021, 14:06

                        • Login

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