Kirsche
18-11-2005, 12:26
Hallo Leute,
ich möchte mit "Select All" eine komplette Tabelle auswählen, damit der Benutzer den Inhalt in die Zwischenablage kopieren kann, ohne dass er selber alles in der Tabelle markieren muss.
Das Markieren klappt auch ohne Probleme (es wird alles blau). Wenn der Inhalt anschließend kopiert werden soll, wird höchstens eine Zahl kopiert, wenn überhaupt. Ich habe es auch mit QSelection versucht, aber auch damit klappt das Kopieren nicht.
Hier ist der Code:
void MyWidget::slotCopy()
{
// copy selection into a string, rows separated by newline characters, columns by tab characters
QTableSelection selection = table->selection( table->currentSelection() );
QString s;
for( int i = 0; i < selection.numRows(); i++ )
{
if( i > 0 )
{
s = s + "\n";
}
for( int j = 0; j < selection.numCols(); j++ )
{
if( j > 0 )
{
s = s + "\t";
}
s = s + table->text( selection.topRow() + i, selection.leftCol() + j );
}
}
// copy data to clipboard
QApplication::clipboard()->setText( s );
}
void MyWidget::slotSelectAll()
{
//table->selectCells( 0, 0, table->numRows() - 1, table->numCols() - 1 );
QTableSelection selection( 0, 0, table->numRows() - 1, table->numCols() - 1 );
table->addSelection( selection );
}
Wenn ich mit der Maus einen Bereich in der Tabelle auswähle, kann ich diesen anschließend auch ohne Probleme kopieren.
Was mache ich falsch?
Vielen Dank,
ich möchte mit "Select All" eine komplette Tabelle auswählen, damit der Benutzer den Inhalt in die Zwischenablage kopieren kann, ohne dass er selber alles in der Tabelle markieren muss.
Das Markieren klappt auch ohne Probleme (es wird alles blau). Wenn der Inhalt anschließend kopiert werden soll, wird höchstens eine Zahl kopiert, wenn überhaupt. Ich habe es auch mit QSelection versucht, aber auch damit klappt das Kopieren nicht.
Hier ist der Code:
void MyWidget::slotCopy()
{
// copy selection into a string, rows separated by newline characters, columns by tab characters
QTableSelection selection = table->selection( table->currentSelection() );
QString s;
for( int i = 0; i < selection.numRows(); i++ )
{
if( i > 0 )
{
s = s + "\n";
}
for( int j = 0; j < selection.numCols(); j++ )
{
if( j > 0 )
{
s = s + "\t";
}
s = s + table->text( selection.topRow() + i, selection.leftCol() + j );
}
}
// copy data to clipboard
QApplication::clipboard()->setText( s );
}
void MyWidget::slotSelectAll()
{
//table->selectCells( 0, 0, table->numRows() - 1, table->numCols() - 1 );
QTableSelection selection( 0, 0, table->numRows() - 1, table->numCols() - 1 );
table->addSelection( selection );
}
Wenn ich mit der Maus einen Bereich in der Tabelle auswähle, kann ich diesen anschließend auch ohne Probleme kopieren.
Was mache ich falsch?
Vielen Dank,