如何在QDockWidget顶部添加工具栏?
我正在尝试在 QdockWidget 创建工具栏。但工具栏中的图标没有放置在正确的位置。它们应该位于标题下方。
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);
如何设置顶部工具栏?
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 ?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
也许您应该尝试向小部件“this”添加布局,然后将“placeholder”小部件添加到布局中。
Maybe you should try adding a layout to the widget "this" ,then put "placeholder" widget to the layout.