Hello Guys,

I'm new to the forum, I really admire the effort you guys put on this and I wish I could take part of it.


I have been struggling with this for about a week now, and still couldnt figure out the right way to doing it.

Here is an example version:

Qt Code:
  1. #include <QApplication>
  2. #include <QTableWidget>
  3.  
  4.  
  5.  
  6. ////////////////////Class Definition////////////////////
  7. class Table: public QTableWidget
  8. {
  9.  
  10. public:
  11. Table(QWidget *parent=0);
  12. void addRowAndMerge(int, int, int);
  13.  
  14. enum {MaxRows=100, MaxColumns=4};
  15. };
  16.  
  17.  
  18. ////////////////////Implementation////////////////////
  19. Table::Table(QWidget *parent): QTableWidget(parent)
  20. {
  21. setRowCount(MaxRows);
  22. setColumnCount(MaxColumns);
  23.  
  24. }
  25.  
  26. //append a nLines line at the end of row and span
  27. void Table::addRowAndMerge(int nLines, int row, int column)
  28. {
  29. int _insertedRows;
  30.  
  31. _insertedRows = rowSpan(row, column); // how many already spanned rows
  32.  
  33. for (int i = 0; i < nLines; i++) { //insert
  34. insertRow(row + _insertedRows + i);
  35. }
  36.  
  37. setSpan(row, column, _insertedRows + nLines-1, 1); //span
  38. }
  39.  
  40.  
  41. ////////////////////Test////////////////////
  42. int main(int argc, char *argv[])
  43. {
  44. QApplication app(argc, argv);
  45.  
  46. Table *tab = new Table;
  47. tab->addRowAndMerge(2, 2, 0); // insert 2 lines at (2, 0)
  48. tab->addRowAndMerge(3, 0, 0); // insert 3 lines at (0, 0)
  49. tab->show();
  50.  
  51. return app.exec();
  52. }
To copy to clipboard, switch view to plain text mode 



The proble is as follows:

Suppose I insert 2 lines after the second line and span the cell at (2,0) to 2.
Now if I insert exactly 3 lines or more at position 0 and span the cell at (0,0) to 3,
everything is ruined up, the result is Horrible !!!

Please if you can suggest me any other way to manage it correctly, I'll be really very Thankfull.