2
我想在右側有工具圖標,而不是頂部。按照我的經驗,我可以手動移動它們,我可以將其設置爲垂直,但它們保持在頂部;我可以設置setAllowedAreas()
這意味着我限制工具欄區域可以駐留的位置,但工具按鈕位於頂部。我需要像setToolbarArea()
這樣的東西。有類似的東西嗎?如何以編程方式將工具按鈕移動到右側工具欄區域?
我想在右側有工具圖標,而不是頂部。按照我的經驗,我可以手動移動它們,我可以將其設置爲垂直,但它們保持在頂部;我可以設置setAllowedAreas()
這意味着我限制工具欄區域可以駐留的位置,但工具按鈕位於頂部。我需要像setToolbarArea()
這樣的東西。有類似的東西嗎?如何以編程方式將工具按鈕移動到右側工具欄區域?
您可以再次撥打addToolBar
來移動工具欄。
如果主窗口已經管理的工具欄,然後它只會在 工具欄移到區域。
I.e.
mainwindow.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
mainwindow.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);
}