0

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 ?

tushar
  • 313
  • 4
  • 10
  • What makes you think that they should appear on top? In your code there's no reason to cause that. – musicamante Feb 28 '22 at 11:06
  • @musicamante: How to make them at top ? Can you tell me ? – tushar Feb 28 '22 at 11:07
  • 2
    [`addWidget()`](https://doc.qt.io/qt-5/qboxlayout.html#addWidget) has a `alignment` argument, use `Qt.AlignTop`. But if you don't plan to put other widgets *on the side* of the toolbar, there's no point in using a horizontal layout: just use a QVBoxLayout and [`addStretch()`](https://doc.qt.io/qt-5/qboxlayout.html#addStretch) after adding the toolbar. – musicamante Feb 28 '22 at 13:48

1 Answers1

0

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