Qt World Summit: Submit your Presentation

How to creat a layout with BOTH a menubar and a tablewidget

  • Hi there,
    I've been trying for a while now: (pyqt5 + pycharm + python 3.5)
    I can create a layout with a menubar up the top (File,Edit,Help) and a simple layout.
    I can also create a layout with a tablewidget no problems.
    BUT I cannot get both to work on the same layout.
    Could someone please show me a simple example of both on a page at the same time?

    thanks in advance

  • Lifetime Qt Champion

    @Saru4 Can you show how you're trying to create this layout?

  • @Saru4
    Are you using setMenuBar() to set the menu bar to your main window?
    This way, you would use:

    • setMenuBar(/menu bar goes here/) to set the menubar to your window;
    • setLayout(/layout goes here/) to set the main layout in your window.

    Then, you can call layout() to get the pointer on the main window's layout, to which you can call addWidget() to add any widget you like.

    If you want to, I can give you a quick example, but it will be a C++ example as I do not master Python very much. But only the syntax changes a bit, the process should be identical. ^^

Log in to reply