采用SARibbon创建简单的ribbon界面
实例代码如下所示:
1、头文件:
#pragma once
#include <SARibbonBar.h>
#include "SARibbonMainWindow.h"
class QTextEdit;
class SAProjectDemo1 : public SARibbonMainWindow
{
Q_OBJECT
public:
SAProjectDemo1(QWidget *parent = Q_NULLPTR);
QAction* createAction(const QString& text, const QString& iconurl);
QTextEdit *mTextedit;
};
2、源文件
#include "SAProjectDemo1.h"
#include <QTextEdit>
#include <QStatusBar>
SAProjectDemo1::SAProjectDemo1(QWidget *parent)
: SARibbonMainWindow(parent)
{
setWindowTitle(("ribbon mainwindow test"));
setRibbonTheme(SARibbonTheme::RibbonThemeOffice2021Blue);
SARibbonBar* pRibbonBar = ribbonBar();
//
SARibbonCategory* page1 = new SARibbonCategory();
page1->setCategoryName("page1");
SARibbonPannel* pannel1 = new SARibbonPannel("pannel1", page1);
{
QAction* act = createAction("Demo", ":/SAProjectDemo1/Res/fullscreen.png");
act->setIconText("save1");
connect(act, &QAction::triggered, this, [this, act]()
{
});
pannel1->addLargeAction(act);
}
{
QAction* act = createAction("Demo", ":/SAProjectDemo1/Res/fullscreen.png");
act->setIconText("save2");
connect(act, &QAction::triggered, this, [this, act]()
{
});
pannel1->addLargeAction(act);
}
{
QAction* act = createAction("Demo", ":/SAProjectDemo1/Res/fullscreen.png");
act->setIconText("save3");
connect(act, &QAction::triggered, this, [this, act]()
{
});
pannel1->addLargeAction(act);
}
page1->addPannel(pannel1);
//
SARibbonPannel* pannel12 = new SARibbonPannel("pannel12", page1);
page1->addPannel(pannel12);
{
QAction* act = createAction("Demo", ":/SAProjectDemo1/Res/fullscreen.png");
act->setIconText("save");
connect(act, &QAction::triggered, this, [this, act]()
{
});
pannel12->addLargeAction(act);
}
pRibbonBar->addCategoryPage(page1);
//
SARibbonCategory* page2 = new SARibbonCategory();
page2->setCategoryName("page2");
SARibbonPannel* pannel2 = new SARibbonPannel("pannel2", page2);
{
QAction* act = createAction("Demo", ":/SAProjectDemo1/Res/fullscreen.png");
act->setIconText("save");
connect(act, &QAction::triggered, this, [this, act]()
{
});
pannel2->addLargeAction(act);
}
page2->addPannel(pannel2);
pRibbonBar->addCategoryPage(page2);
mTextedit = new QTextEdit(this);
setCentralWidget(mTextedit);
//
setStatusBar(new QStatusBar());
resize(800, 600);
}
QAction* SAProjectDemo1::createAction(const QString& text, const QString& iconurl)
{
QAction* act = new QAction(this);
act->setText(text);
act->setIcon(QIcon(iconurl));
act->setObjectName(text);
return act;
}