Objects organised in a matrix
-
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... :-(
@MortyMars
QLayoutItem *QGridLayout::itemAtPosition(int row, int column) const
followed by
QWidget *QLayoutItem::widget() const
on the returnedQLayoutItem, will give you theQTextEditor whatever is there. Useqobject_cast<QTextEdit *>(widget)on the widget to check if it is/access it as aQTextEdit*. -
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... :-(
@MortyMars ... or use the apporach @Pl45m4 already wrote above and store them in your own container.
-
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... :-(
@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
QTextEditsin 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 yourQTextEditsdirectly 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"); -
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... :-(
@MortyMars
...Or :) ... If you all want to do is iterate theQTextEdits, not know/care which one is which (e.g. you're setting some attribute on them all)QList<QTextEdit *> allTextEdits = parentWidget.findChildren<QTextEdit *>(); ``` -
@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
QTextEditsin 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 yourQTextEditsdirectly 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");@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?
-
@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?
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. -
@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?
@MortyMars said in Objects organised in a matrix:
How can I get the QTextEdit from my form?
In your
mainWindowwithui->objectname
(the name you see in QtDesigner, liketextEdit_10).
I recommend to rename them, so you know what widget is where. -
@MortyMars said in Objects organised in a matrix:
How can I get the QTextEdit from my form?
In your
mainWindowwithui->objectname
(the name you see in QtDesigner, liketextEdit_10).
I recommend to rename them, so you know what widget is where.@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");> `` -
@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");> ``@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().
-
@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().
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 :-)
-
M MortyMars has marked this topic as solved on