Unsolved Store content of QTableWidget into a buffer variable
-
Hello,
I have a configuration window with a table to add some filter options. A user can add more filter with an "Add" Button to the table. The filter rules getting stored after the user pressed a "OK" button. If the user close the window without pressing "OK" the new input should be discarded.
The current implementation doesn´t discard the new input after closing the window. My idea is to store the table into a buffer when the user is pressing the "OK" buffer and load this buffer when the user open the configuration window again.I write this method to store the current table to the buffer:
void Filter::saveTable( void ) { tableBuffer->setRowCount(ui->tableWidget->rowCount()); tableBuffer->setColumnCount(ui->tableWidget->columnCount()); for(int i_Row = 0; i_Row < ui->tableWidget->rowCount(); i_Row++) { for(int i_Column = 0; i_Column < ui->tableWidget->colorCount(); i_Column++) { QTableWidgetItem* Item = ui->tableWidget->item(i_Row, i_Column); tableBuffer->setItem(i_Row, i_Column, Item); } } }
I got this message when I try to save the current table from the ui into the buffer:
QPaintDevice::metrics: Device has no metric information
What is the problem? Does Qt support a better solution to discard changes in a table when the table window got closed without pressing "OK"?
-
Hi
Are you sure
"QPaintDevice::metrics: Device has no metric information"
comes from this code?Also,
QTableWidgetItem* Item = ui->tableWidget->item(i_Row, i_Column);
tableBuffer->setItem(i_Row, i_Column, Item);So u take the item from one TableWidget and insert into another table?
Im not sure it works as we think as then its shared between 2 widgets?
So both will try to delete it?- Does Qt support a better solution to discard changes in a table
Well not pr automatic, but normally you would have data (the filters) in its own class/list.
Then when open the Editor, load data to the table
If user dont press ok, simply not save table back to master data list. -
Hello
yes I´m sure, because I doesn´t get this message anymore after removing this lines.
Reloading the data is a better idea I think. Thank you for this hint. I think I will solve it in this way. -
@Kampi
Hi
ok. its just it sound like something with painting and all you
do is adding items. But must be indirectly then.
seems to come from qpaintdevice.cpp
ifndef Q_WS_QPA
int QPaintDevice::metric(PaintDeviceMetric) const
{
qWarning("QPaintDevice::metrics: Device has no metric information");
return 0;
}
#endifSo seems its simply not compiled in?
Anyway, hopefully it will go away with your new design :)
-
@Kampi
Hello,
You have a typo in this line:for(int i_Column = 0; i_Column < ui->tableWidget->colorCount(); i_Column++)
Change colorCount() to columnCount()