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. Map multiple rows with multiple widgets
Forum Updated to NodeBB v4.3 + New Features

Map multiple rows with multiple widgets

Scheduled Pinned Locked Moved Solved General and Desktop
map
9 Posts 4 Posters 2.6k Views 3 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.
  • M Offline
    M Offline
    Mr. Kibu
    wrote on 24 May 2016, 06:09 last edited by Mr. Kibu
    #1

    Hi,

    I have got a QSqlTableModel with multiple rows (e.g. 3 rows). Now I want to map the data with multiple widgets. Each row should map to one widget, the mapped widget should be placed horizontal side by side. It should look like this:

    tree widgets

    I create the widgets side by side like this:

        numberOfRows = model->rowCount();
    
        // add a widget for each row
        for (int i=0;i<numberOfRows;++i)
        {
            myWidget = new RowWidget();
            ui->QLayout->addWidget(myWidget);
        }
    

    How do I map the data with the widgets, to show in one widget the data of one row (and if I edit the data in the widget the result will be submited to the database)

    Thank you!

    Franz

    1 Reply Last reply
    0
    • M Offline
      M Offline
      michelson
      wrote on 24 May 2016, 06:44 last edited by
      #2

      I would do it in the myWidget constructor, just add parameters for everything you need, assuming the link you provided constructor canlook like:

      explicit  myWidget(QString row1, int row2, double row2, QWidget* parent = 0);
      

      and than just bind data when creating them in for loop.

      1 Reply Last reply
      0
      • S Offline
        S Offline
        SGaist
        Lifetime Qt Champion
        wrote on 24 May 2016, 07:06 last edited by
        #3

        Hi,

        Looks like a job for QDataWidgetMapper

        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
        3
        • M Offline
          M Offline
          Mr. Kibu
          wrote on 24 May 2016, 07:30 last edited by
          #4

          Yes, I thought also in this direction. I have tried this:

              numberOfRows = model->rowCount();
          
              mapper = new QDataWidgetMapper(this);
              mapper->setModel(model);
              mapper->setItemDelegate(new QSqlRelationalDelegate(mapper));
          
              // add a widget for each row
              for (int i=0;i<numberOfRows;++i)
              {
                  myWidget = new RowWidget();
                  ui->QLayout->addWidget(myWidget);
          
                  mapper->addMapping(myWidget->SpinBox,2);
                  mapper->addMapping(myWidget->DoubleSpinBox,3);
              }
          
             mapper->toFirst();
          

          But the code above did not worked correct (I have in every widget the data of the last row!!). How do I install the mapper to have in every widget the data of one row?

          1 Reply Last reply
          0
          • S Offline
            S Offline
            SGaist
            Lifetime Qt Champion
            wrote on 24 May 2016, 08:54 last edited by
            #5

            Use one mapper per RowWidget.

            One solution would be to have the mapper itself in RowWidget, have a setModel and a setRow method also in RowWidget so you can build them and change the row used by the mapper as you wish.

            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
            • M Offline
              M Offline
              Mr. Kibu
              wrote on 24 May 2016, 11:36 last edited by
              #6

              I did it! I added the QDataWidgetMapper in the constructor of RowWidget. On creating the myWidget in the for loop, I commit the rowID of the row which is shown in the widget.

              Thanks to all!

              K 1 Reply Last reply 24 May 2016, 11:38
              0
              • M Mr. Kibu
                24 May 2016, 11:36

                I did it! I added the QDataWidgetMapper in the constructor of RowWidget. On creating the myWidget in the for loop, I commit the rowID of the row which is shown in the widget.

                Thanks to all!

                K Offline
                K Offline
                kshegunov
                Moderators
                wrote on 24 May 2016, 11:38 last edited by
                #7

                @Mr.-Kibu
                Have in mind that QDataWidgetMapper has a known bug/deficiency when working with relational sql model and having a combo box for the foreign key.

                Read and abide by the Qt Code of Conduct

                1 Reply Last reply
                0
                • M Offline
                  M Offline
                  Mr. Kibu
                  wrote on 24 May 2016, 11:45 last edited by
                  #8

                  Thank you for the info, I don't know that. Where can I get more informations about this bug?

                  K 1 Reply Last reply 24 May 2016, 11:48
                  0
                  • M Mr. Kibu
                    24 May 2016, 11:45

                    Thank you for the info, I don't know that. Where can I get more informations about this bug?

                    K Offline
                    K Offline
                    kshegunov
                    Moderators
                    wrote on 24 May 2016, 11:48 last edited by kshegunov
                    #9

                    @Mr.-Kibu
                    Take a look at this thread.

                    EDIT: Also this bug report.

                    Read and abide by the Qt Code of Conduct

                    1 Reply Last reply
                    0

                    9/9

                    24 May 2016, 11:48

                    • Login

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