Wie kann ich ein QTableWidget so erstellen, dass sich die Spalten automatisch an den vorhandenen Platz im Fenster anpassen?
Code: Alles auswählen
# -*- coding: cp1252 -*-
import sys
from PyQt4 import QtGui, QtCore
class MainWindow(QtGui.QMainWindow):
def __init__(self):
QtGui.QMainWindow.__init__(self)
self.resize(350, 250)
self.setWindowTitle(appname)
#textEdit = QtGui.QTextEdit()
headers = ["KUNDE", "STANDORT", "PRODUKT", "VERSION", "BEMERKUNG"]
dataGrid = QtGui.QTableWidget()
dataGrid.setRowCount(15)
dataGrid.setColumnCount(len(headers))
dataGrid.setAlternatingRowColors(True)
dataGrid.setHorizontalHeaderLabels(headers)
self.setCentralWidget(dataGrid)
exit = QtGui.QAction(QtGui.QIcon('res/toolbar/exit.png'), 'Beenden', self)
exit.setShortcut('Ctrl+Q')
exit.setStatusTip(appname + ' beenden')
self.connect(exit, QtCore.SIGNAL('triggered()'), QtCore.SLOT('close()'))
self.statusBar()
menubar = self.menuBar()
file = menubar.addMenu('&Datei')
file.addAction(exit)
toolbar = self.addToolBar('Beenden')
toolbar.addAction(exit)
appname = "PyQT Table"
app = QtGui.QApplication(sys.argv)
main = MainWindow()
main.show()
sys.exit(app.exec_())