PDA

View Full Version : QTableWidget span !



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.

stephanyShulter
20th October 2008, 13:43
I Suppose it's a bug what can you say ?

Please can I have some indications :(

stephanyShulter
27th October 2008, 14:20
Resolved !!

Ive just installed QtX11 4.4.3 it did save my life.
A new function was introduced called clearSpans()

so before adding any row, I save old span informations in a temprorary buffer, I call clearSpans(), insert line and restore old infos.

If you are encountering the same probleme, here is it resolved :p