Regarding Signals and Slots
-
Using a custom model(QAbstractModel), there you need to override setData.
-
@Shruthi said in Regarding Signals and Slots:
But how to change the value of the tableWidget, when user changes by typing into the tableWidget.
If the user types into a cell, the data should be changed correspondingly. Or do you mean the user cannot type into a cell in your table widget?
-
@JonB The user can change the value in the table widget, Based on the user entered value, the respective columns and rows value changes.
The function is ready. But, I am not able to link both of it.
Thank you
@Shruthi Can you record a gif video with an example?
-
@JonB The user can change the value in the table widget, Based on the user entered value, the respective columns and rows value changes.
The function is ready. But, I am not able to link both of it.
Thank you
@Shruthi said in Regarding Signals and Slots:
@JonB The user can change the value in the table widget, Based on the user entered value, the respective columns and rows value changes.
The function is ready. But, I am not able to link both of it.Given your first sentence, I do not know what your second sentence means or what the problem is.
-
@TheGringerEye @JonB To make it simple,the values are prefilled in the tableWidget, once the app is launched.
If user is not interested in the prefilled value in the tableWidget. User can change the value in the widget.
So based on the value changed by the user, The same value needs to be copied to all rows and columns.
Please let me know, how to solve this.
Thank you
-
@TheGringerEye @JonB To make it simple,the values are prefilled in the tableWidget, once the app is launched.
If user is not interested in the prefilled value in the tableWidget. User can change the value in the widget.
So based on the value changed by the user, The same value needs to be copied to all rows and columns.
Please let me know, how to solve this.
Thank you
-
void QTableWidget::cellChanged(int row, int column)
This signal is emitted whenever the data of the item in the cell specified by row and column has changed.
-
Ok. o.O
void MainWindow::on_tableWidget_itemChanged(QTableWidgetItem *item) { int numCols = ui->tableWidget->columnCount(); int numRows = ui->tableWidget->rowCount(); auto newValue = item->text(); for (int row = 0; row < numRows; ++row) { for (int col = 0; col < numCols ; ++col) { auto cellItem = ui->tableWidget->item(row, col); if (cellItem) cellItem->setText(newValue); } } }
-
Ok. o.O
void MainWindow::on_tableWidget_itemChanged(QTableWidgetItem *item) { int numCols = ui->tableWidget->columnCount(); int numRows = ui->tableWidget->rowCount(); auto newValue = item->text(); for (int row = 0; row < numRows; ++row) { for (int col = 0; col < numCols ; ++col) { auto cellItem = ui->tableWidget->item(row, col); if (cellItem) cellItem->setText(newValue); } } }
-
@mrjj I am using the same section of code which you have mentioned above, It is working. But before user changes the value in the tablewidget, it is filling with some garbage value. Please let me know,what is the issue? Our changes is interfering with the insertion step itself. How to avoid this?
-
@mrjj I am using the same section of code which you have mentioned above, It is working. But before user changes the value in the tablewidget, it is filling with some garbage value. Please let me know,what is the issue? Our changes is interfering with the insertion step itself. How to avoid this?
@Shruthi
HI
I think the signal will also trigger when you fill the table.To avoid that.
Either fill the table BEFORE you connect the signal.or block its signals while filling it
https://doc.qt.io/qt-5/qsignalblocker.html -
@Shruthi
HI
I think the signal will also trigger when you fill the table.To avoid that.
Either fill the table BEFORE you connect the signal.or block its signals while filling it
https://doc.qt.io/qt-5/qsignalblocker.html