PDA

View Full Version : swap cell widgets on QTableWidget



ulmly
26th February 2009, 13:49
Hi all !

I want to swap cell widgets. I have used cellWidget to get the widget of cell, insertRow to create the purposed row, setCellWidget to assign the widget to the new row, and removeRow to delete the current row.

However deleting the old one deletes also the cell widget at the purposed row. :crying:

I have looked for the archive and found this http://www.qtcentre.org/forum/f-qt-programming-2/t-qtablewidget-move-row-3386-post18492.html but still unanswered :confused:

Any helps would be highly appreciated. Thank you. :)

jpn
26th February 2009, 16:54
What do you need those cell widgets for? Maybe there's a better way to do it without cell widgets? Cell widgets don't integrate to the table very well, they are just something laid on top of the view. And they are expensive to maintain. I'd advice against using them in the first place...

ulmly
26th February 2009, 17:56
I need those widgets for graphically assinging the order of tasks (please see the attached figure). The code was originally written with Qt3 and will be now ported to Qt4.

In fact I have tried to used the Q3Table for supporting the Qt3's QTable, but the widgets are somehow freezed when the window size is altered. That's why I have decided to use Qt4. However, I should keep as most lines of code as possible.

jpn
26th February 2009, 18:08
Where's the table and what is it used for? All I can see is a layout of widgets... :)

ulmly
26th February 2009, 19:18
That is the table with type of QTableWidget. The table has two columns and, at the beginning only one row with the 'Subtask' widget as the fix one. The other task widgets, each widget for each row, are added by request. The order of task widgets, except the 'Subtask', should be able to alter: up or down.

Also, in Qt3, this altering order can be done perfectly by applying function swapCells(), which is no longer available on Qt4. That is the main problem.

Any idea ?

ulmly
27th February 2009, 06:52
Should I use QTableView rather than QTableWidget because of having cell widgets ? I know that the latter inherits the former and works with default model. In other words, QTableView should be used for working with a table using own data model.

Unfortunately I am not sure that in my case this is the answer.

Any helps would be highly appreciated.

jpn
27th February 2009, 08:47
My point was that I don't see the table used for anything but "layouting" the widgets. As I said, filling a table with cell widgets is not optimal. Do you actually use any table specific features? Shouldn't you use a layout to do layouting?

ulmly
27th February 2009, 11:10
The table is not shown because of the thickness of the border line of each cell. In order to make easier to recognize the table, please see the attachment. The border lines are in red. In this case, I have 3 rows and 2 columns.

The property of table used in this case is the index of row, which is representing the order of tasks. The Subtask widget is fixed at the bottom.

I am not sure that Layout can handle such a problem. When so, which one ?

faldzip
27th February 2009, 12:14
My guess would be to use e.g. QScrollArea with grid layout if you dont need model (as I understand it right).

ulmly
5th March 2009, 10:18
I have decided to be back to use of Q3Table. The freezing problem occuring whenever the size window is altered is solved by means of function resizeEvent().

Thanks anyway.