Search code examples
pythonqtpysideqtoolbar

Add a toolbar to the left side of the main window in PySide


I'm building a GUI using Pyside. I'm trying to add a toolbar to the left side of my main window. This code works for adding a toolbar on top:

toolbarBox = self.addToolBar('boxAdjustment')

However, I want to customize it to locate at the left side. I tried the code below. It doesn't give me an error, but no toolbar shows up.

toolbarBox = QtGui.QToolBar('boxAdjustment')
self.addToolBar(QtCore.Qt.LeftToolBarArea , toolbarBox)

"self" is a QMainWindow object in the code snippets above. Do you know how I can fix it?


Solution

  • The way to achieve this is

    toolbarBox = QtGui.QToolBar(self)
    self.addToolBar(QtCore.Qt.LeftToolBarArea, toolbarBox)
    

    You were close but the argument in QToolBar(argument) is actually the parent window, not a string or the toolbar name.