PDA

View Full Version : QTableWidget swapping rows with widgets in cells



dnnc
23rd May 2007, 16:17
Hi to all,
This is my first post, although I have followed this forum for some time and resolved many problems thanks to it.

I have a one column QTableWidget with each cell in a row containing a QwtPlot inside. I want to move up/down a plot in the table, so instead of using removeRow and insertRow, because the former deletes the plot inside the cell, I used in Qt 4.1.0 the following (simplified) code which works, given that setCellWidget just overrides the previous widget with the new one without deleting the previous one.



void SignalPlotFrame::moveUp(int row)
{
if (row > 0)
{
QwtPlot *plotOne = static_cast<QwtPlot*>(
table->cellWidget (row - 1, 0));
QwtPlot *plotTwo = static_cast<QwtPlot*>(
table->cellWidget (row, 0));
table->setCellWidget (row - 1, 0, plotTwo);
table->setCellWidget (row, 0, plotOne);
}
}

Testing the same code with Qt 4.2.1, it does not work any more, and looking at the implementation of QTableWidget::setCellWidget and QAbstractItemView::setIndexWidget I saw that it changed from 4.1.0 and that now it first tests whether there was a widget in the cell before setting the new one, and if so it deletes it.

Is it possible with QTableWidget to remove/overright the old widget from a cell without deleting it? Or should I better invest some effort in implementing my own model/view/delegate classes for handling such situations?

wysota
24th May 2007, 14:11
I think Qwt gives you a way to plot directly on a painter so implementing a delegate doing so should be easy.