C++ 如何以编程方式将工具按钮移动到右侧工具栏区域?
我希望工具图标位于右侧,而不是顶部。根据我的经验,我可以手动移动它们,我可以将它们的C++ 如何以编程方式将工具按钮移动到右侧工具栏区域?,c++,qt,qt5,C++,Qt,Qt5,我希望工具图标位于右侧,而不是顶部。根据我的经验,我可以手动移动它们,我可以将它们的方向();我可以设置setAllowedAreas(),这意味着我限制工具栏区域可以驻留的位置,但工具按钮位于顶部。我需要类似于setToolbarArea()的东西。是否有类似的功能?您可以再次调用addToolBar来移动工具栏 据报道, 如果主窗口已经管理工具栏,那么它将只移动 工具栏到区域 即 main window.h #ifndef MAINWINDOW_H #define MAINWINDOW_H
方向();我可以设置setAllowedAreas()
,这意味着我限制工具栏区域可以驻留的位置,但工具按钮位于顶部。我需要类似于setToolbarArea()
的东西。是否有类似的功能?您可以再次调用addToolBar
来移动工具栏
据报道,
如果主窗口已经管理工具栏,那么它将只移动
工具栏到区域
即
main window.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
#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);
}