Search code examples
pythonpyqtpositiontoolbar

Position QWidgets in toolbar with PyQt


I am trying to position some buttons in a toolbar, on my application. As you can see in these images, I need to put one of them in the right side, opposing the others. Something, like this:

This is the toolbar that I have: This is the toolbar

And I need to move, for example, the QLabel to the right side: enter image description here

Is there any way to do this? I've tried setGeometry and move methods, but I can't accomplish this. Hope you can help me


Solution

  • Add an expanding spacer widget before the label:

    spacer = QtGui.QWidget(self)
    spacer.setSizePolicy(QtGui.QSizePolicy.Expanding, QtGui.QSizePolicy.Expanding)
    toolbar.addWidget(spacer)
    toolbar.addWidget(label)