Search code examples
c++qtqtoolbar

How do I align a QWidget to the right of a QToolBar?


I have some QWidget (QLineEdit), and I would like to align it to the right of my QToolbar.

Is there any simple way to do it?


Solution

  • Try putting a spacer widget before it:

    QToolBar* toolBar = new QToolBar("Toolbar");
    
    QWidget* spacer = new QWidget();
    spacer->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
    toolBar->addWidget(spacer);
    
    // now add your actions or widgets after the spacer widget