如何以编程方式将工具按钮移动到右侧工具栏区域
How to move programmatically tool buttons to right toolbar area?
我希望工具图标在右侧,而不是顶部。正如我所经历的,我可以手动移动它们,我可以将它们orientation()
设置为垂直,但它们仍位于顶部;我可以设置setAllowedAreas()
这意味着我限制了工具栏区域可以驻留的位置,但工具按钮位于顶部。我需要像setToolbarArea()
这样的东西.有类似的东西吗?
您可以再次调用addToolBar
来移动工具栏。
根据文件,
如果主窗口已经管理工具栏,那么它只会移动 工具栏到区域。
即
主窗口.h
#ifndef MAINWINDOW_H
#define MAINWINDOW_H
#include <QMainWindow>
namespace Ui {
class MainWindow;
}
class MainWindow : public QMainWindow
{
Q_OBJECT
public:
explicit MainWindow(QWidget *parent = 0);
~MainWindow();
private:
Ui::MainWindow *ui;
QToolBar * toolBar;
public slots:
void moveLeft();
void moveRight();
};
#endif // MAINWINDOW_H
主窗口.cpp
#include "mainwindow.h"
#include "ui_mainwindow.h"
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
ui->setupUi(this);
toolBar= new QToolBar("Tool Bar");
toolBar->addAction(QIcon(":/qt.png"), "FirstAction", this, SLOT(moveLeft()));
toolBar->addAction(QIcon(":/qt.png"), "SecondAction", this, SLOT(moveRight()));
addToolBar(Qt::RightToolBarArea, toolBar);
}
MainWindow::~MainWindow()
{
delete ui;
}
void MainWindow::moveLeft()
{
addToolBar(Qt::LeftToolBarArea, toolBar);
}
void MainWindow::moveRight()
{
addToolBar(Qt::RightToolBarArea, toolBar);
}
相关文章:
- 将对象移动到std::shared_ptr
- 何时在引用或唯一指针上使用移动语义
- 如何从具有移动语义的类对象中生成共享指针
- 将shared_ptr移动到<StructA>shared_ptr<变体<结构A、结构 B>>
- C / C++ 移位/偏移/向左或向右移动位图?
- MSVC将仅移动结构参数解释为指针
- 自定义先决条件对移动分配运算符有效吗
- 返回值优化:显式移动还是隐式
- 当有分配器意识的容器被复制/移动时,反弹分配器是否被复制/移走
- 为什么复制而不是移动数据元素?
- 可以使用移动语义更改或改进此C++代码吗?
- 使lambda不可复制/不可移动
- c++在使用指针时移动语义
- 将QGraphicsItem的移动区域限制在多边形区域内
- 如何在移动列表视图中添加滚动条?并且用户只能垂直滚动特定区域
- 如何禁用窗口在区域内移动
- DXGI 桌面复制 API 何时将区域标识为移动区域
- 如何以编程方式将工具按钮移动到右侧工具栏区域
- CTreeCtrl -改变其位置而不移动整个区域
- Qt:限制QGraphicsItem在另一个QGraphicsItem中的可移动区域