PDA

View Full Version : QItemSelection, does not copy all area



Mnemonic
26th March 2010, 09:41
Hi, I have strange problem. I have two class: mainWindow inherits by QMainWindow, and myWidget inherits by QWidget. In mainWindow class i create model, and myWidget class i create QTableView. Now i would like copy selection, but not in myWidget, only mainWindow class, so i did something like this in myWidget:


connect(table->selectionModel(),SIGNAL(
selectionChanged(const QItemSelection &,const QItemSelection &)),
this,SIGNAL(updateSelect(const QItemSelection &,const QItemSelection &)));


And in mainWindow:


connect(widget,SIGNAL(updateSelect(const QItemSelection &,const QItemSelection &)),
this,SLOT(updateSelection(const QItemSelection&,const QItemSelection &)));

void mainWindow::updateSelection(const QItemSelection &selection,const QItemSelection &){
this->selection = selection;
}

void mainWindow::copyCells(){
QList<QItemSelectionRange> models = selection;
if(models.isEmpty())
return;
QModelIndex start = models[0].topLeft();
QModelIndex stop = models[0].bottomRight();
QString text;
for(int i=start.row(); i<=stop.row(); ++i) {
for(int j=start.column(); j<=stop.column(); ++j) {
if(model->item(i,j)->text() != "="){
text+= model->item(i,j)->text();
text += ' ';
}
}
text += '\n';
}
QApplication::clipboard()->setText(text);
}

Now, when i select an area and try copy, it copy random value, further only one left or right column, or top or bottom row. Function copyCells works well, i tested it earlier. Where I make error?