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. Objects organised in a matrix

Objects organised in a matrix

Scheduled Pinned Locked Moved Solved General and Desktop
17 Posts 4 Posters 1.2k 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.
  • MortyMarsM MortyMars

    @Christian-Ehrlicher

    Thanks for your help

    But I was hoping - and this is the whole point of the initial question - to access the textEdit by a reference to its position in the grid rather than by its name, which would allow me to process iteratively rather than object by object.

    If that's not possible, I admit I don't see the point of grouping Widgets in these grids... :-(

    JonBJ Offline
    JonBJ Offline
    JonB
    wrote on last edited by JonB
    #8

    @MortyMars
    QLayoutItem *QGridLayout::itemAtPosition(int row, int column) const
    followed by
    QWidget *QLayoutItem::widget() const
    on the returned QLayoutItem, will give you the QTextEdit or whatever is there. Use qobject_cast<QTextEdit *>(widget) on the widget to check if it is/access it as a QTextEdit*.

    1 Reply Last reply
    1
    • MortyMarsM MortyMars

      @Christian-Ehrlicher

      Thanks for your help

      But I was hoping - and this is the whole point of the initial question - to access the textEdit by a reference to its position in the grid rather than by its name, which would allow me to process iteratively rather than object by object.

      If that's not possible, I admit I don't see the point of grouping Widgets in these grids... :-(

      Christian EhrlicherC Offline
      Christian EhrlicherC Offline
      Christian Ehrlicher
      Lifetime Qt Champion
      wrote on last edited by
      #9

      @MortyMars ... or use the apporach @Pl45m4 already wrote above and store them in your own container.

      Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
      Visit the Qt Academy at https://academy.qt.io/catalog

      1 Reply Last reply
      0
      • MortyMarsM MortyMars

        @Christian-Ehrlicher

        Thanks for your help

        But I was hoping - and this is the whole point of the initial question - to access the textEdit by a reference to its position in the grid rather than by its name, which would allow me to process iteratively rather than object by object.

        If that's not possible, I admit I don't see the point of grouping Widgets in these grids... :-(

        Pl45m4P Offline
        Pl45m4P Offline
        Pl45m4
        wrote on last edited by Pl45m4
        #10

        @MortyMars said in Objects organised in a matrix:

        to access the textEdit by a reference to its position in the grid rather than by its name, which would allow me to process iteratively rather than object by object.

        Put your QTextEdits in a container like:

        @Pl45m4 said in Objects organised in a matrix:

        QVector< QVector< QTextEdit * > > m_textEditMatrix;

        Either you take them from your Designer file and add them in your code.
        Or you code your QTextEdits directly and add them to your layout also by code.

        QVector< QVector< QTextEdit * > > m_textEditMatrix;
        QTextEdit * edit_0_0 = new QTextEdit(this);
        QTextEdit * edit_0_1 = new QTextEdit(this);
        QTextEdit * edit_0_2 = new QTextEdit(this);
        QTextEdit * edit_1_0 = new QTextEdit(this);
        QTextEdit * edit_1_1 = new QTextEdit(this);
        QTextEdit * edit_1_2 = new QTextEdit(this);
        
        // Add a loop that fills your matrix
        QVector<QTextEdit*> tmpRow;
        tmpRow.push_back(edit_0_0);
        tmpRow.push_back(edit_0_1);
        tmpRow.push_back(edit_0_2);
        m_textEditMatrix.push_back(tmpRow);
        
        // test with:
        int row, col;
        row = 0;
        col = 1;
        m_textEditMatrix.at(row).at(col)->setText("True");
        
        

        If debugging is the process of removing software bugs, then programming must be the process of putting them in.

        ~E. W. Dijkstra

        MortyMarsM 1 Reply Last reply
        1
        • MortyMarsM MortyMars

          @Christian-Ehrlicher

          Thanks for your help

          But I was hoping - and this is the whole point of the initial question - to access the textEdit by a reference to its position in the grid rather than by its name, which would allow me to process iteratively rather than object by object.

          If that's not possible, I admit I don't see the point of grouping Widgets in these grids... :-(

          JonBJ Offline
          JonBJ Offline
          JonB
          wrote on last edited by
          #11

          @MortyMars
          ...Or :) ... If you all want to do is iterate the QTextEdits, not know/care which one is which (e.g. you're setting some attribute on them all)

          QList<QTextEdit *> allTextEdits = parentWidget.findChildren<QTextEdit *>();
          ```
          1 Reply Last reply
          0
          • Pl45m4P Pl45m4

            @MortyMars said in Objects organised in a matrix:

            to access the textEdit by a reference to its position in the grid rather than by its name, which would allow me to process iteratively rather than object by object.

            Put your QTextEdits in a container like:

            @Pl45m4 said in Objects organised in a matrix:

            QVector< QVector< QTextEdit * > > m_textEditMatrix;

            Either you take them from your Designer file and add them in your code.
            Or you code your QTextEdits directly and add them to your layout also by code.

            QVector< QVector< QTextEdit * > > m_textEditMatrix;
            QTextEdit * edit_0_0 = new QTextEdit(this);
            QTextEdit * edit_0_1 = new QTextEdit(this);
            QTextEdit * edit_0_2 = new QTextEdit(this);
            QTextEdit * edit_1_0 = new QTextEdit(this);
            QTextEdit * edit_1_1 = new QTextEdit(this);
            QTextEdit * edit_1_2 = new QTextEdit(this);
            
            // Add a loop that fills your matrix
            QVector<QTextEdit*> tmpRow;
            tmpRow.push_back(edit_0_0);
            tmpRow.push_back(edit_0_1);
            tmpRow.push_back(edit_0_2);
            m_textEditMatrix.push_back(tmpRow);
            
            // test with:
            int row, col;
            row = 0;
            col = 1;
            m_textEditMatrix.at(row).at(col)->setText("True");
            
            
            MortyMarsM Offline
            MortyMarsM Offline
            MortyMars
            wrote on last edited by
            #12

            @Pl45m4 said in Objects organised in a matrix:

            @Pl45m4 @Christian-Ehrlicher @JonB :
            Thank you all for trying to help me, especially as I'm clearly not at the right level to understand everything instantly, but I'll keep at it, I promise.

            Either you take them from your Designer file and add them in your code.

            How can I get the QTextEdit from my form?

            JonBJ Pl45m4P 2 Replies Last reply
            0
            • MortyMarsM MortyMars

              @Pl45m4 said in Objects organised in a matrix:

              @Pl45m4 @Christian-Ehrlicher @JonB :
              Thank you all for trying to help me, especially as I'm clearly not at the right level to understand everything instantly, but I'll keep at it, I promise.

              Either you take them from your Designer file and add them in your code.

              How can I get the QTextEdit from my form?

              JonBJ Offline
              JonBJ Offline
              JonB
              wrote on last edited by
              #13

              @MortyMars

              How can I get the QTextEdit from my form?

              When you use Designer all the widgets you create and name go into ui->, e.g. ui->textEdit1.

              1 Reply Last reply
              0
              • MortyMarsM MortyMars

                @Pl45m4 said in Objects organised in a matrix:

                @Pl45m4 @Christian-Ehrlicher @JonB :
                Thank you all for trying to help me, especially as I'm clearly not at the right level to understand everything instantly, but I'll keep at it, I promise.

                Either you take them from your Designer file and add them in your code.

                How can I get the QTextEdit from my form?

                Pl45m4P Offline
                Pl45m4P Offline
                Pl45m4
                wrote on last edited by Pl45m4
                #14

                @MortyMars said in Objects organised in a matrix:

                How can I get the QTextEdit from my form?

                In your mainWindow with

                ui->objectname
                (the name you see in QtDesigner, like textEdit_10).
                I recommend to rename them, so you know what widget is where.


                If debugging is the process of removing software bugs, then programming must be the process of putting them in.

                ~E. W. Dijkstra

                MortyMarsM 1 Reply Last reply
                0
                • Pl45m4P Pl45m4

                  @MortyMars said in Objects organised in a matrix:

                  How can I get the QTextEdit from my form?

                  In your mainWindow with

                  ui->objectname
                  (the name you see in QtDesigner, like textEdit_10).
                  I recommend to rename them, so you know what widget is where.

                  MortyMarsM Offline
                  MortyMarsM Offline
                  MortyMars
                  wrote on last edited by
                  #15

                  @Pl45m4
                  Here's the code I've come up with.
                  The compilation runs smoothly, but I can't see any changes to the content of the QTextEdit in my form...

                  `QVector< QVector< QTextEdit* >> m_textEditMatrix;
                      ui->edit_0_0 = new QTextEdit(this);
                      ui->edit_0_1 = new QTextEdit(this);
                      ui->edit_0_2 = new QTextEdit(this);
                      ui->edit_0_3 = new QTextEdit(this);
                      ui->edit_0_4 = new QTextEdit(this);
                      ui->edit_0_5 = new QTextEdit(this);
                  
                      // Add a loop that fills your matrix
                      QVector<QTextEdit*> tmpRow;
                      tmpRow.push_back(ui->edit_0_0);
                      tmpRow.push_back(ui->edit_0_1);
                      tmpRow.push_back(ui->edit_0_2);
                      tmpRow.push_back(ui->edit_0_3);
                      tmpRow.push_back(ui->edit_0_4);
                      tmpRow.push_back(ui->edit_0_5);
                  
                  
                      m_textEditMatrix.push_back(tmpRow);
                  
                      // test with:
                      //int row, col;
                      //row = 0;
                      //col = 0;
                      m_textEditMatrix.at(0).at(0)->setText("True");
                      m_textEditMatrix.at(0).at(1)->setText("True");
                      m_textEditMatrix.at(0).at(2)->setText("True");
                      m_textEditMatrix.at(0).at(3)->setText("True");
                      m_textEditMatrix.at(0).at(4)->setText("True");
                      m_textEditMatrix.at(0).at(5)->setText("True");>
                  ``
                  Christian EhrlicherC 1 Reply Last reply
                  0
                  • MortyMarsM MortyMars

                    @Pl45m4
                    Here's the code I've come up with.
                    The compilation runs smoothly, but I can't see any changes to the content of the QTextEdit in my form...

                    `QVector< QVector< QTextEdit* >> m_textEditMatrix;
                        ui->edit_0_0 = new QTextEdit(this);
                        ui->edit_0_1 = new QTextEdit(this);
                        ui->edit_0_2 = new QTextEdit(this);
                        ui->edit_0_3 = new QTextEdit(this);
                        ui->edit_0_4 = new QTextEdit(this);
                        ui->edit_0_5 = new QTextEdit(this);
                    
                        // Add a loop that fills your matrix
                        QVector<QTextEdit*> tmpRow;
                        tmpRow.push_back(ui->edit_0_0);
                        tmpRow.push_back(ui->edit_0_1);
                        tmpRow.push_back(ui->edit_0_2);
                        tmpRow.push_back(ui->edit_0_3);
                        tmpRow.push_back(ui->edit_0_4);
                        tmpRow.push_back(ui->edit_0_5);
                    
                    
                        m_textEditMatrix.push_back(tmpRow);
                    
                        // test with:
                        //int row, col;
                        //row = 0;
                        //col = 0;
                        m_textEditMatrix.at(0).at(0)->setText("True");
                        m_textEditMatrix.at(0).at(1)->setText("True");
                        m_textEditMatrix.at(0).at(2)->setText("True");
                        m_textEditMatrix.at(0).at(3)->setText("True");
                        m_textEditMatrix.at(0).at(4)->setText("True");
                        m_textEditMatrix.at(0).at(5)->setText("True");>
                    ``
                    Christian EhrlicherC Offline
                    Christian EhrlicherC Offline
                    Christian Ehrlicher
                    Lifetime Qt Champion
                    wrote on last edited by
                    #16

                    @MortyMars said in Objects organised in a matrix:

                    ui->edit_0_0 = new QTextEdit(this);
                    ui->edit_0_1 = new QTextEdit(this);
                    ui->edit_0_2 = new QTextEdit(this);
                    ui->edit_0_3 = new QTextEdit(this);
                    ui->edit_0_4 = new QTextEdit(this);
                    ui->edit_0_5 = new QTextEdit(this);
                    

                    Why? They are already created within ui.setupUi().

                    Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
                    Visit the Qt Academy at https://academy.qt.io/catalog

                    MortyMarsM 1 Reply Last reply
                    1
                    • Christian EhrlicherC Christian Ehrlicher

                      @MortyMars said in Objects organised in a matrix:

                      ui->edit_0_0 = new QTextEdit(this);
                      ui->edit_0_1 = new QTextEdit(this);
                      ui->edit_0_2 = new QTextEdit(this);
                      ui->edit_0_3 = new QTextEdit(this);
                      ui->edit_0_4 = new QTextEdit(this);
                      ui->edit_0_5 = new QTextEdit(this);
                      

                      Why? They are already created within ui.setupUi().

                      MortyMarsM Offline
                      MortyMarsM Offline
                      MortyMars
                      wrote on last edited by
                      #17

                      @Christian-Ehrlicher,

                      I confess, I've stupidly copied and adapted the code provided for objects that don't yet exist.
                      By commenting out the unnecessary lines, IT WORKS !

                      Thank you all very much for your support and patience, I'll be able to move forward, and if I need to I'll know where to find you :-)

                      1 Reply Last reply
                      0
                      • MortyMarsM MortyMars has marked this topic as solved on

                      • Login

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