PyQt custom widget not showing

后端 未结 2 1668
傲寒
傲寒 2021-01-25 03:40

I\'m new to PyQt.

I\'m trying to put a QTableView in a class, so I can define it\'s behaviour in the class without mixing it with all the other code, but when I do so it

2条回答
  •  温柔的废话
    2021-01-25 04:28

    the problem: table.view has no parent. If you add self.view.show() to test to Table.initUi(), you get two widgets, MyWindow with empty table as tmoreau wrote and table.view as isolated widget.

    You can either pass a parent when constructing table.view in Table.initUi()

    self.view = QTableView(self) 
    

    (then you don't need a layout) or add table.view to a layout as written by tmoreau, Then the tableview is reparented.

    Removing the class has the same effect, then the tableview is added to layout.

提交回复
热议问题