How to add tool bar at the top in QDockWidget?

187 views Asked by At

I am trying to create tool bar at QdockWidget. But the icons in tool bar are not getting placed at proper position. They should come just below the title.

    QWidget* placeholder = new QWidget();

    QBoxLayout* toolLayout = new QBoxLayout(QBoxLayout::LeftToRight,placeholder);
    toolLayout->setContentsMargins(0, 0, 0, 0);
    auto toolbar = new QToolBar;
    toolLayout->addWidget(toolbar);

    const QIcon newIcon = QIcon::fromTheme("document-new", QIcon(":/img/copy1.png"));
    QAction* zoomIn = new QAction(newIcon, tr("&Zoom In"), this);

    const QIcon newIcon1 = QIcon::fromTheme("document-new", QIcon(":/img/cut1.png"));
    QAction* zoomOut = new QAction(newIcon1, tr("&Zoom Out"), this);

    toolbar->addAction(zoomIn);
    toolbar->addAction(zoomOut);

    setWidget(placeholder);



  

How to set tool bar at the top ?

1

There are 1 answers

0
Limbo_Jolly On

Maybe you should try adding a layout to the widget "this" ,then put "placeholder" widget to the layout.