[PySide] Nicely resizing a QTableWidget inside a QMainWindow
Carl Chenet
chaica at ohmytux.com
Tue Aug 21 23:25:40 CEST 2012
On 21/08/2012 15:21, Thomas-Karl Pietrowski wrote:
> Hey ;)
>
> I haven't tested your code exactly, but it seems that you missed to add
> a layout between your mainwindow and your table widget.
> Try to add one and I hope it helps.
Thanks for your help. I tried the following adding a qvboxlayout but it
didn't improve. I'm not sure I'm using it in a correcdt way though.
class Draw(QMainWindow):
def __init__(self):
QMainWindow.__init__(self)
columnnames = ['...']
tableWidget = QTableWidget(len(lines), len(columnnames))
tableWidget.setHorizontalHeaderLabels(columnnames)
for line in lines:
newItem1 = QTableWidgetItem(player)
tableWidget.setItem(nbplayers, 0, newItem1)
...
tableWidget.resizeColumnsToContents()
tableWidget.resizeRowsToContents()
# define the action of the menu bar
exitaction = QAction(QIcon('exit.png'), '&Exit', self)
exitaction.setShortcut('Ctrl+Q')
exitaction.setStatusTip('Exit application')
exitaction.triggered.connect(self.close)
self.statusBar()
# define the menu bar
menubar = self.menuBar()
filemenu = menubar.addMenu('&Commands')
filemenu.addAction(exitaction)
# define the table as central in the window
layout = QVBoxLayout()
layout.addWidget(tableWidget)
self.setCentralWidget(tableWidget)
self.setWindowTitle('myapp')
self.setLayout(layout)
self.show()
Regards,
Carl Chenet
More information about the PySide
mailing list