[PySide] Nicely resizing a QTableWidget inside a QMainWindow

Thomas-Karl Pietrowski thopiekar at gmail.com
Tue Aug 21 15:21:53 CEST 2012


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.

On Di., 21. Aug. 2012 15:01:14 CEST, chaica at ohmytux.com wrote:

> Hi,
> 
> I've got some issues with   QTableWidget inside a QMainWindow.
> 
> My problem is that when resizing the main window, the QTableWidget 
> does not follow and does not resize accordingly to its main window. I 
> tried several ways to correct it but could not succeed. Help will be 
> greatly appreciated.
> 
> The code follows:
> 
> class DrawTrackerth(QMainWindow):
>         def __init__(self):
>                 QMainWindow.__init__(self)
> 
>                 # create a QT table widget with len(players) numbers of rows 
> and 4 columns
>                 ...some stuff
>                 columnnames = ['foo', 'bar']
>                 tableWidget = QTableWidget(len(lines), len(columnnames))
>                 tableWidget.setHorizontalHeaderLabels(columnnames)
>                 for line in lines:
>                         newItem1 = QTableWidgetItem(line)
>                         tableWidget.setItem(..., 0, newItem1)
>                         newItem2 = QTableWidgetItem(line)
>                         tableWidget.setItem(..., 1, newItem2)
>                 tableWidget.resizeColumnsToContents()
>                 tableWidget.resizeRowsToContents()
>                 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
>                 self.setCentralWidget(tableWidget)
>                 self.setWindowTitle('MyApp')
>                 self.resize(800,600)
>                 self.show()
> 
> Regards,
> Carl Chenet
> 
> _______________________________________________
> PySide mailing list
> PySide at qt-project.org
> http://lists.qt-project.org/mailman/listinfo/pyside

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.qt-project.org/pipermail/pyside/attachments/20120821/1277ce1f/attachment.html>


More information about the PySide mailing list