How can i know how many rows span my selection in a table??
Im my case, i have a qtexttable. When i select some cells, i'd like to know how many rows the selecion spans.......any idea???
Printable View
How can i know how many rows span my selection in a table??
Im my case, i have a qtexttable. When i select some cells, i'd like to know how many rows the selecion spans.......any idea???
Which widgets are you using? In general you can query for the item selection and you will be given all the selected indexes/items. Take a look at QItemSelection for example, there are some methods there that should work for you.
I use a QGraphicsTextItem Object filled with a QTextTable.
I don't find any method of this class that i can use to obtain the specific behaviour.
I think that the "mergeCells" function, inside it, makes the work i'm looking for.
...infact, it just uses the reference to a QTextCursor Object to find out how many rows and columns the selection spans.
QGraphicsTextItem dont have the same qtextcursor selection as Qtextedit or QtextBrowser
on version 4.2. on later version i not know...
I rewrite the TextApi and run on this way....
http://www.qt-apps.org/content/show....?content=80234
Code:
void Layoutpainter::SetColumLarge() { if (textCursor().currentTable()) { int cellcoolcursoris = existingcell.column(); /* int value start from zero */ bool ok; tr("Point Length:"),Get_Cell_Width(tbforms,cellcoolcursoris), 1, 2000, 1, &ok); if (ok && LargeSet > 0) { QVector<QTextLength> constraints = tbforms.columnWidthConstraints(); for (int i = 0; i < constraints.size(); ++i) { if (i == cellcoolcursoris) { } } tbforms.setColumnWidthConstraints(constraints); textCursor().currentTable()->setFormat(tbforms); } } } { qreal notfound = 0; QVector<QTextLength> constraints = TableFormat.columnWidthConstraints(); for (int i = 0; i < constraints.size(); ++i) { if (i == position) { return langecell.rawValue(); } } } return notfound; } void Layoutpainter::MergeCellByCursorPosition() { if (textCursor().currentTable()) { textCursor().currentTable()->mergeCells(textCursor()); } } void Layoutpainter::RemoveCoolByCursorPosition() { if (textCursor().currentTable()) { int cellcoolcursoris = existingcell.column(); /* int value start from zero */ int cellrowcursoris = existingcell.row(); /* int value start from zero */ textCursor().currentTable()->removeColumns(cellcoolcursoris,1); } } void Layoutpainter::RemoveRowByCursorPosition() { if (textCursor().currentTable()) { int cellcoolcursoris = existingcell.column(); /* int value start from zero */ int cellrowcursoris = existingcell.row(); /* int value start from zero */ textCursor().currentTable()->removeRows(cellrowcursoris,1); } } void Layoutpainter::AppendTableRows() { bool ok = false; if (textCursor().currentTable()) { int cellcoolcursoris = existingcell.column(); /* int value start from zero */ int cellrowcursoris = existingcell.row(); /* int value start from zero */ int approwtot = QInputDialog::getInteger(0, tr("Append NR. line row"),tr("Row:"), 1, 1, 100, 1, &ok); if (ok && approwtot > 0) { textCursor().currentTable()->insertRows(cellrowcursoris + 1,approwtot); } } } void Layoutpainter::AppendTableCools() { bool ok = false; if (textCursor().currentTable()) { int cellcoolcursoris = existingcell.column(); /* int value start from zero */ int cellrowcursoris = existingcell.row(); /* int value start from zero */ int appcooltot = QInputDialog::getInteger(0, tr("Table append Column"),tr("Cool:"), 1, 1, 10, 1, &ok); if (ok && appcooltot > 0) { textCursor().currentTable()->insertColumns(cellcoolcursoris + 1,appcooltot); } } } void Layoutpainter::SetTableCellColor() { if (textCursor().currentTable()) { bool ok; /* reformat this -> existingcell */ /* get color */ QColor col = QColorDialog::getRgba(textCursor().currentTable()->cellAt(textCursor()).format().background().color().rgba(),&ok, 0); if (!col.isValid()) { return; } existformat.setBackground(stylesin); existingcell.setFormat(existformat); } }
anyone of these functions resolv my problem......
problem resolved........here is the code!!
Code:
int a,numrows,c,d; textCursor().selectedTableCells(&a,&numrows,&c,&d);