getText QLineEdit in tableWidget
-
Hi!
I've been created a table with tableWidget and I also insert QLineEdit in every cell.
But now I need to retrive the text written in the QLineEdits.
Like if someone write in the second cell of the first row, how can I retrive the value of that QLineEdit?This is how my table is implemanted (with 2columns added via parametri.ui):
Parametri::Parametri(QWidget *parent) : QDialog(parent), ui(new Ui::Parametri) { ui->setupUi(this); setWindowTitle("Parametri"); for(int row=0;row<=21;row++){ val = new QLineEdit(this); ui->tableWidget->setCellWidget(row,0,val); val->setAlignment(Qt::AlignCenter); val->setText("8.00"); } }Thanks for anyone who can help me
-
Hi!
I've been created a table with tableWidget and I also insert QLineEdit in every cell.
But now I need to retrive the text written in the QLineEdits.
Like if someone write in the second cell of the first row, how can I retrive the value of that QLineEdit?This is how my table is implemanted (with 2columns added via parametri.ui):
Parametri::Parametri(QWidget *parent) : QDialog(parent), ui(new Ui::Parametri) { ui->setupUi(this); setWindowTitle("Parametri"); for(int row=0;row<=21;row++){ val = new QLineEdit(this); ui->tableWidget->setCellWidget(row,0,val); val->setAlignment(Qt::AlignCenter); val->setText("8.00"); } }Thanks for anyone who can help me
@aim0d What is wrong with https://doc.qt.io/qt-6/qtablewidget.html#cellWidget and https://doc.qt.io/qt-6/qlineedit.html#text-prop ?
-
@aim0d What is wrong with https://doc.qt.io/qt-6/qtablewidget.html#cellWidget and https://doc.qt.io/qt-6/qlineedit.html#text-prop ?
-
@jsulm Nothing is wrong with them.
I just start learning QT, sorry if I dont know every function.
Thnks.@aim0d said in getText QLineEdit in tableWidget:
sorry if I dont know every function
It is fine to not to know every function, but you can easilly find these two functions in the documentation.
Usually, if there is a setSomething() method there is also a something() method. -
@aim0d said in getText QLineEdit in tableWidget:
sorry if I dont know every function
It is fine to not to know every function, but you can easilly find these two functions in the documentation.
Usually, if there is a setSomething() method there is also a something() method.@jsulm I've tried with the CellWidget, like this:
qDebug() << ui->tableWidget->cellWidget(3,0);Just to see the first output. And this is what it's showing in the terminal
QLineEdit(0x58e6f30)But I'm not understanding how to show the text inside the QLineEdit.
-
@jsulm I've tried with the CellWidget, like this:
qDebug() << ui->tableWidget->cellWidget(3,0);Just to see the first output. And this is what it's showing in the terminal
QLineEdit(0x58e6f30)But I'm not understanding how to show the text inside the QLineEdit.
@aim0d said in getText QLineEdit in tableWidget:
But I'm not understanding how to show the text inside the QLineEdit.
That was the second link I gave you: https://doc.qt.io/qt-6/qlineedit.html#text-prop
Of course you will need to cast the pointer returned by cellWidget to QLineEdit*.QWidget(0x0) - looks like there is no widget set in 1,2? And if I look at your loop you only have one column, not 3...
-
@aim0d said in getText QLineEdit in tableWidget:
But I'm not understanding how to show the text inside the QLineEdit.
That was the second link I gave you: https://doc.qt.io/qt-6/qlineedit.html#text-prop
Of course you will need to cast the pointer returned by cellWidget to QLineEdit*.QWidget(0x0) - looks like there is no widget set in 1,2? And if I look at your loop you only have one column, not 3...
@jsulm Yeah, I edited because I was catching some try I did in the mainWindow.
I tried with the second link u sent me but having trouble (thanks to my being noob).
now i was trying with thisqDebug() << val->displayText();
But as expected, it shows every text of every QLineEdit.Of course you will need to cast the pointer returned by cellWidget to QLineEdit*
That I have to look how to do it
Thks 4 your help
-
@jsulm Yeah, I edited because I was catching some try I did in the mainWindow.
I tried with the second link u sent me but having trouble (thanks to my being noob).
now i was trying with thisqDebug() << val->displayText();
But as expected, it shows every text of every QLineEdit.Of course you will need to cast the pointer returned by cellWidget to QLineEdit*
That I have to look how to do it
Thks 4 your help
@aim0d said in getText QLineEdit in tableWidget:
But as expected, it shows every text of every QLineEdit.
Is this not what you want/what do you want?
Like if someone write in the second cell of the first row, how can I retrive the value of that QLineEdit?
If this is what you mean, then only look at "the second cell of the first row", not every cell?
-
@aim0d said in getText QLineEdit in tableWidget:
But as expected, it shows every text of every QLineEdit.
Is this not what you want/what do you want?
Like if someone write in the second cell of the first row, how can I retrive the value of that QLineEdit?
If this is what you mean, then only look at "the second cell of the first row", not every cell?
Is this not what you want/what do you want?
No, I would like to have for a single cell
If this is what you mean, then only look at "the second cell of the first row", not every cell?
That's what I'm not understanding how to do it and asking
How do I focus just one cell and print the text, not the Widget? -
Is this not what you want/what do you want?
No, I would like to have for a single cell
If this is what you mean, then only look at "the second cell of the first row", not every cell?
That's what I'm not understanding how to do it and asking
How do I focus just one cell and print the text, not the Widget?@aim0d
Well if you only want to know about one cell specify its row, columncellWidget(row, column)instead of going through some loop!QTextEdit *textEdit = qobject_cast<QTextWidget *>(ui->tableWidget->cellWidget(row, column)); if (textEdit) qDebug() << textEdit->text(); -
@aim0d
Well if you only want to know about one cell specify its row, columncellWidget(row, column)instead of going through some loop!QTextEdit *textEdit = qobject_cast<QTextWidget *>(ui->tableWidget->cellWidget(row, column)); if (textEdit) qDebug() << textEdit->text();