#include <QApplication>
#include <QTableWidget>
////////////////////Class Definition////////////////////
{
public:
void addRowAndMerge(int, int, int);
enum {MaxRows=100, MaxColumns=4};
};
////////////////////Implementation////////////////////
{
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[])
{
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();
}
#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();
}
To copy to clipboard, switch view to plain text mode
Bookmarks