ich habe derzeit ein Problem mit QTableWidget.
In meinem Programm versuche ich die dem QTableWidget-Objekt
hinzugefügten QWidgets (= CellWidgets) nach einer bestimmten
Layoutfolge
neu anzuordnen, sobald ein bestimmtes QWidget entfernt worden ist.horizontal [Anordnung von links nach rechts; nach unten fortlaufend] bzw.
vertikal [Anordnung von oben nach unten; nach rechts fortlaufend]
Die Neuanordnung sieht dabei vor, dass alle nach dem zu löschenden QWidget folgenden
QWidgets um eine Stelle (gemäß der gesetzten Layoutausrichtung) nach hinten
verschoben werden.
Das Problem dabei ist, dass nach Durchführung meiner Funktion die behandelten
QWidgets nicht mehr in den entspr. Zellen angezeigt werden.
=> Ausgenommen davon ist komischerweise immer das letzte behandelte QWidget.
Anm.: Nicht genutzte Zeilen werden gelöscht.
Zu meiner Funktion:
Code: Alles auswählen
// DATA
QTableWidget table;
// METHOD
bool removeWidget(QWidget *widget)
{
// for the horizontal direction
if(direction == Horizontal)
{
for(int globalRow=0; globalRow<table->rowCount(); globalRow++)
{
for(int globalCol=0; globalCol<table->columnCount(); globalCol++)
{
QWidget *temp = table->cellWidget(globalRow, globalCol);
if(temp != NULL && temp == widget)
{
// reorganize existing slots
if(!isEmpty()) /*for the table*/
{
// only treat widgets coming after the one which has to be
// deleted
int colStart = globalCol;
for(int row=globalRow; row<table->rowCount(); row++)
{
for(int col=colStart; col<table->columnCount(); col++)
{
if(table->cellWidget(row, col) != NULL)
{
// for all cells of a row (beside the first one)
if(row > globalRow && col > 0)
table->setCellWidget(row, col-1, table->cellWidget(row, col));
// for the first cell of all other rows
else if(row > globalRow && col == 0)
table->setCellWidget(row-1, table->columnCount()-1, table->cellWidget(row, col));
// for the first row (special case)
else if(row == globalRow && col > globalCol)
table->setCellWidget(row, col-1, table->cellWidget(row, col));
}
}
// reset colStart
if(colStart > 0)
colStart = 0;
}
}
// adjust the table's grid (if necessary)
if(slotCount%table->columnCount() == 0)
{
// remove last (empty) row
if(table->rowCount() > 1)
table->setRowCount(table->rowCount()-1);
}
return true;
}
}
}
}
// for the vertical direction
else
{
// ... do something
}
return false;
}
Hoffe jemand kennt eine Lösung!
Bedanke mich für sinnvolle Hilfe schon mal im Vorraus.