The toolbar filling the whole width of the main window is a standard Qt behaviour. You can probably override it by not using QMainWindow but rather placing the toolbar manually on the widget but that's not very convenient. What do you need such behaviour for?