forrealthough
forrealthough

Reputation: 47

How to create a table on a tab on PyQt5?

In my "main" class I have this

tabs = Tabs(self.db)
self.setCentralWidget(tabs)

where I create a tab and show it, with Tabs inheriting QTabWidget. On the Tabs class I have this

self.livros = QWidget()
self.pessoas = QWidget()
self.addTab(self.livros, 'Livros')
self.addTab(self.pessoas, 'Pessoas')

tabela = Tabela(self.db)

where I add two tabs to my tabs. In each of them I'd like to exhibit a table. I created one table class (QTableWidget) called Tabela, where I set rows and columns and stuff, but I have no idea of how to add this table to the tabs. If I instead use it on the setCentralWidget on my main screen it works fine, but again, I'd like to exhibit in the tabs. How could I accomplish this (considering QTabWidget can't have a setCentralWidget)? Thanks very much!

Upvotes: 1

Views: 1571

Answers (1)

forrealthough
forrealthough

Reputation: 47

I'm finding out this pattern of solving out my problem minutes after posting a question here. Anyways, the solution was pretty simple: The method setParent. On the class Tabs:

self.livros = QWidget()
self.pessoas = QWidget()

tabela = Tabela(self.db)
tabela.setParent(self.livros)

self.addTab(self.livros, 'Livros')
self.addTab(self.pessoas, 'Pessoas')

Hope this helps someone.

Upvotes: 1

Related Questions