stephanyShulter
19th October 2008, 00:04
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:
#include <QApplication>
#include <QTableWidget>
////////////////////Class Definition////////////////////
class Table: public QTableWidget
{
public:
Table(QWidget *parent=0);
void addRowAndMerge(int, int, int);
enum {MaxRows=100, MaxColumns=4};
};
////////////////////Implementation////////////////////
Table::Table(QWidget *parent): QTableWidget(parent)
{
setRowCount(MaxRows);
setColumnCount(MaxColumns);
}
//append a nLines line at the end of row and span
void Table::addRowAndMerge(int nLines, int row, int column)
{
int _insertedRows;
_insertedRows = rowSpan(row, column); // how many already spanned rows
for (int i = 0; i < nLines; i++) { //insert
insertRow(row + _insertedRows + i);
}
setSpan(row, column, _insertedRows + nLines-1, 1); //span
}
////////////////////Test////////////////////
int main(int argc, char *argv[])
{
QApplication app(argc, argv);
Table *tab = new Table;
tab->addRowAndMerge(2, 2, 0); // insert 2 lines at (2, 0)
tab->addRowAndMerge(3, 0, 0); // insert 3 lines at (0, 0)
tab->show();
return app.exec();
}
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.
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:
#include <QApplication>
#include <QTableWidget>
////////////////////Class Definition////////////////////
class Table: public QTableWidget
{
public:
Table(QWidget *parent=0);
void addRowAndMerge(int, int, int);
enum {MaxRows=100, MaxColumns=4};
};
////////////////////Implementation////////////////////
Table::Table(QWidget *parent): QTableWidget(parent)
{
setRowCount(MaxRows);
setColumnCount(MaxColumns);
}
//append a nLines line at the end of row and span
void Table::addRowAndMerge(int nLines, int row, int column)
{
int _insertedRows;
_insertedRows = rowSpan(row, column); // how many already spanned rows
for (int i = 0; i < nLines; i++) { //insert
insertRow(row + _insertedRows + i);
}
setSpan(row, column, _insertedRows + nLines-1, 1); //span
}
////////////////////Test////////////////////
int main(int argc, char *argv[])
{
QApplication app(argc, argv);
Table *tab = new Table;
tab->addRowAndMerge(2, 2, 0); // insert 2 lines at (2, 0)
tab->addRowAndMerge(3, 0, 0); // insert 3 lines at (0, 0)
tab->show();
return app.exec();
}
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.