Search code examples
qtqt-designer

How to add a QMenuBar to QWidget in QtDesigner


Problem:
I have a custom Window Hint within QMainWindow, I need to place QMenuBar under a row of layout
This is how it looks now
enter image description here
And how it looks like in QtDesigner
enter image description here

Question:
How to place QMenuBar under custom task bar


Solution

  • First of all, there's no way to do this right in QtDesigner
    I found a way to replace it by directly changing *.ui file

    First step is to open *.ui file in text editor (I'm using PyCharm with *.xml extension)

    Second step is look how grid layout works, basically it built like
    HTML tag with few options like row, column, rowspan, colspan
    first two of them are position of the item and other two for positioning
    enter image description here

    Following step is to find our QMenuBar widget (my is on 142-154 lines)
    enter image description here
    copy and move on

    Then we need to create a new item tag in layout tag
    enter image description here
    This is the beginning of layout tag, create a tag after it

    Then add coordinates of QMenuBar that you want (mine is row="1" column="0" colspan="5")
    enter image description here
    And paste QMenuBar tag into it, then correct indentation
    enter image description here
    Now save the file and look at it in QtDesigner
    enter image description here

    Using PyUic reveals none problem