#include #include #include int main( int argc, char *argv[] ) { QApplication app( argc, argv ); QTableWidget table; // Größe festlegen table.setRowCount( 5 ); table.setColumnCount( 5 ); // Zellen mit Produkten als Text füllen for( int i = 0; i < table.rowCount(); i++ ) { for( int j = 0; j < table.columnCount(); j++ ) table.setItem( i, j, new QTableWidgetItem( QString::number( ( i + 1 ) * ( j + 1) ) ) ); } // Die Größe der Zellen in der Tabelle hängt vom Inhalt ab table.resizeRowsToContents(); table.resizeColumnsToContents(); // Die Tabelle soll vollständig angezeigt werden, ohne eine // Scrollbar anzuzeigen. // https://stackoverflow.com/a/37615363 // https://stackoverflow.com/a/40300974 table.setSizePolicy( QSizePolicy::Minimum, QSizePolicy::Minimum ); table.setVerticalScrollBarPolicy( Qt::ScrollBarAlwaysOff ); table.setHorizontalScrollBarPolicy( Qt::ScrollBarAlwaysOff ); table.setFixedSize( table.horizontalHeader()->length() + table.verticalHeader()->width() + table.frameWidth() * 2, table.verticalHeader()->length() + table.horizontalHeader()->height() + table.frameWidth() * 2 ); // Titel setzen und Widget anzeigen table.setWindowTitle( "TableWidget" ); table.show(); return app.exec(); }