Qt-interest Archive, June 2007
Removing rows from table with multiselection
Message 1 in thread
Hello list,
I'm using QT3.3.4 with SuSE Linux 9.3.
I have implemented a small Dialog with a QTable widget. The selection
mode is MultiRow.
If an user has selected different rows and want delete it, the table
removes not all rows.
Let me show a ascii art example
0: Bla | Fasel | Foo
1: ---- | ----- | ---
2: Bar | ----- | ---
3: --- | ----- | ---
4: --- | ----- | ---
5: --- | ----- | ---
6: Hum | ----- | bug
7: --- | ----- | ---
8: --- | ----- | ---
9: --- | ----- | ---
10: --- | ----- | ---
The user first select empty row 1, then he select with Control and
mouse button pressed,
rows 3 to 5, and after that the rows 7 to 10.
If he than press Key_Delete the rows 10 to 6 will be removed.
Here the code snipped from keyPressEvent()
[code]
case Qt::Key_Delete:
if ( tabTemplate->hasFocus() )
{
int numSel = tabTemplate->numSelections();
for ( int c = numSel-1; c >= 0; c-- )
{
s = tabTemplate->selection( c );
if ( s.numRows() > 0 )
{
for ( i = s.bottomRow(); i >= s.topRow(); i-- )
{
if ( i >= 0 )
tabTemplate->removeRow(i);
}
}
}
}
break;
[/code]
numSelections() returns 3 selection which is correct.
Selection 2 ist active and the rows 10 to 7 will be removed.
Next selection 1 is inactive (why?) and nothing happens.
Next selection 0 has only one row which is correct but the row is
number 6 and not 1.
So my question is what happens ? Why is selection 1 inactive ? Should
I implement
the selection programmatically?
Wolfgang
--
[ signature omitted ]