having trouble with QTableWidgetSelectionRange?
-
hello,
I have a question about QTableWidgetSelectionRange, mainly about what a selection range is (I know, really noob question). so is a selection range basically a range of all the cells from one point to another ie: topleft row of 3 to the bottom right column of 5, or does the range consist of the topleft row, and bottom right column of each and every single individual cell within the range, for example: cell [3, 4], cell[3, 5], etc.
the reason why i am asking is because in a book i am reading called "c++ programming a gui with qt4 second edition" the author says that the selection will only consist of one cell, however the implemintation is desighned for multiple cells. here is the code:
void Spreadsheet::copy() { QTableWidgetSelectionRange range = selectedRange(); QString str; for(int i = 0; i < range.rowCount(); i++) { if(i > 0) { str += "\n"; } for(int j = 0; j < range.columnCount(); j++) { if(j > 0) { str += "\t"; } str += formula(range.topRow() + i, range.leftColumn() + j); } } QApplication::clipboard()->setText(str); }
selectedRange:
QTableWidgetSelectionRange Spreadsheet::selectedRange() const { QList<QTableWidgetSelectionRange> ranges = selectedRanges(); if(ranges.isEmpty()) { return QTableWidgetSelectionRange(); } return ranges.first(); }
the first function is desighned to iterate through all the rows of the range, implying there is more than one. however in the selectedRange() function, the author only returns range.first().
any help is greatly appreciated
-
Hi,
Unless we are not reading the same paragraph, you misunderstood it. It says that there will be only one range not only one cell selected.