Hi,
I have a QTableWidget with QTextBrowser inherit Widgets on its cells. But when I want to delete a Item I can't reconnect the rest of items.
The code of remove function is the next:
void Itinerario::on_eliminarToolButton_clicked(){
desconectarWaypoints();
for(int i=0;i<waypoints->rowCount();i++){
WaypointItem *item=static_cast<WaypointItem*>(waypoints->cellWidget(i, TEXTBROWSER_CELLITEM));
if(item->selected()){
if(QMessageBox::question(this,
"",
"Esta seguro de que desea eliminar el Waypoint?",
item->disconnect();
waypoints->removeRow(i);
setWindowModified(true);
}
return;
}
}
reconectarWaypoints();
}
void Itinerario::on_eliminarToolButton_clicked(){
desconectarWaypoints();
for(int i=0;i<waypoints->rowCount();i++){
WaypointItem *item=static_cast<WaypointItem*>(waypoints->cellWidget(i, TEXTBROWSER_CELLITEM));
if(item->selected()){
if(QMessageBox::question(this, "", "Esta seguro de que desea eliminar el Waypoint?",
QMessageBox::Yes, QMessageBox::No)==QMessageBox::Yes){
item->disconnect();
waypoints->removeRow(i);
setWindowModified(true);
}
return;
}
}
reconectarWaypoints();
}
To copy to clipboard, switch view to plain text mode
The code of remove connections is:
void Itinerario::desconectarWaypoints(){
for(int i=0;i<waypoints->rowCount();i++){
WaypointItem *item=static_cast<WaypointItem*>(waypoints->cellWidget(i, TEXTBROWSER_CELLITEM));
item->disconnect();
}
}
void Itinerario::desconectarWaypoints(){
for(int i=0;i<waypoints->rowCount();i++){
WaypointItem *item=static_cast<WaypointItem*>(waypoints->cellWidget(i, TEXTBROWSER_CELLITEM));
item->disconnect();
}
}
To copy to clipboard, switch view to plain text mode
And the code of reconnect connections finally is:
void Itinerario::reconectarWaypoints(){
for(int i=0;i<waypoints->rowCount();i++){
WaypointItem *item=static_cast<WaypointItem*>(waypoints->cellWidget(i, TEXTBROWSER_CELLITEM));
connect(item, SIGNAL(clicked(WaypointItem*, int)), SLOT(waypointClicked(WaypointItem*, int)));
connect(item, SIGNAL(doubleClick(WaypointItem*, int)), SLOT(waypointDoubleClicked(WaypointItem*, int)));
connect(item, SIGNAL(modifiedChange(bool)), parent(), SLOT(setWindowModified(bool)));
}
}
void Itinerario::reconectarWaypoints(){
for(int i=0;i<waypoints->rowCount();i++){
WaypointItem *item=static_cast<WaypointItem*>(waypoints->cellWidget(i, TEXTBROWSER_CELLITEM));
connect(item, SIGNAL(clicked(WaypointItem*, int)), SLOT(waypointClicked(WaypointItem*, int)));
connect(item, SIGNAL(doubleClick(WaypointItem*, int)), SLOT(waypointDoubleClicked(WaypointItem*, int)));
connect(item, SIGNAL(modifiedChange(bool)), parent(), SLOT(setWindowModified(bool)));
}
}
To copy to clipboard, switch view to plain text mode
I want to reconnect because if I dont do remove-reconnect the connection of removed item appears to be here.
Thanks
Bookmarks