Skip to content

Commit

Permalink
SARibbonCategory可通过qss设置背景颜色
Browse files Browse the repository at this point in the history
  • Loading branch information
czyt1988 committed Dec 17, 2023
1 parent 97d128b commit c754b20
Show file tree
Hide file tree
Showing 7 changed files with 23 additions and 17 deletions.
2 changes: 2 additions & 0 deletions src/SARibbonBar/SARibbonCategory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -228,12 +228,14 @@ void SARibbonCategory::PrivateData::doWheelEvent(QWheelEvent* event)

SARibbonCategory::SARibbonCategory(QWidget* p) : QWidget(p), d_ptr(new SARibbonCategory::PrivateData(this))
{
setAttribute(Qt::WA_StyledBackground);
setLayout(new SARibbonCategoryLayout(this));
}

SARibbonCategory::SARibbonCategory(const QString& name, QWidget* p)
: QWidget(p), d_ptr(new SARibbonCategory::PrivateData(this))
{
setAttribute(Qt::WA_StyledBackground);
setLayout(new SARibbonCategoryLayout(this));
setCategoryName(name);
}
Expand Down
8 changes: 4 additions & 4 deletions src/SARibbonBar/resource/theme-dark.qss
Original file line number Diff line number Diff line change
Expand Up @@ -28,17 +28,17 @@ SARibbonCtrlContainer {
}

/*SARibbonCategory*/
SARibbonCategory {
background-color: #b2b2b2;
}
SARibbonCategory:focus {
outline: none;
}

SARibbonCategory {
background-color: #b2b2b2;
}


/*SARibbonStackedWidget*/
SARibbonStackedWidget{
background-color: #b2b2b2;
border-top-width: 0px;
}
SARibbonStackedWidget:focus{
Expand Down
7 changes: 3 additions & 4 deletions src/SARibbonBar/resource/theme-office2013.qss
Original file line number Diff line number Diff line change
Expand Up @@ -27,17 +27,16 @@ SARibbonCtrlContainer {
}

/*SARibbonCategory*/
SARibbonCategory {
background-color: #fcfdfe;
}
SARibbonCategory:focus {
outline: none;
}

SARibbonCategory {
background-color: #fcfdfe;
}

/*SARibbonStackedWidget*/
SARibbonStackedWidget {
background-color: white;
border: 1pt solid #c5d2e0;
border-top-width: 0px;
}
Expand Down
7 changes: 3 additions & 4 deletions src/SARibbonBar/resource/theme-office2016-blue.qss
Original file line number Diff line number Diff line change
Expand Up @@ -95,13 +95,13 @@ SARibbonCtrlContainer {
}

/*SARibbonCategory*/
SARibbonCategory:focus {
outline: none;
}

SARibbonCategory {
background-color: #f1f1f1;/* {Category.BKColor} */
}
SARibbonCategory:focus {
outline: none;
}


/*SARibbonCategoryScrollButton*/
Expand Down Expand Up @@ -131,7 +131,6 @@ SARibbonPannel > SARibbonButtonGroupWidget {

/*SARibbonStackedWidget*/
SARibbonStackedWidget {
background-color: #f1f1f1;/* {Category.BKColor} */
border: 1pt solid #f1f1f1;/* {Category.BorderColor} */
border-top-width: 0px;
}
Expand Down
1 change: 0 additions & 1 deletion src/SARibbonBar/resource/theme-office2021-blue.qss
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,6 @@ SARibbonPannel > SARibbonButtonGroupWidget {

/*SARibbonStackedWidget*/
SARibbonStackedWidget {
background-color: #ffffff;/* {Category.BKColor} */
border: 1pt solid #ffffff;/* {Category.BorderColor} */
border-top-width: 0px;
}
Expand Down
1 change: 0 additions & 1 deletion src/SARibbonBar/resource/theme-win7.qss
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ SARibbonCategory{

/*SARibbonStackedWidget*/
SARibbonStackedWidget{
background-color: white;
border-top-width: 0px;
}
SARibbonStackedWidget:focus{
Expand Down
14 changes: 11 additions & 3 deletions src/example/MainWindowExample/mainwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
#include <QTextStream>
#include <QXmlStreamWriter>
#include <QMessageBox>
#include <QShortcut>
#define PRINT_COST_START() \
QElapsedTimer __TMP_COST; \
__TMP_COST.start(); \
Expand Down Expand Up @@ -509,12 +510,17 @@ void MainWindow::createCategoryMain(SARibbonCategory* page)
SARibbonPannel* pannelStyle = page->addPannel(("ribbon style"));

QAction* actSave = createAction(tr("Save"), ":/icon/icon/save.svg");
actSave->setShortcut(QKeySequence(QLatin1String("Ctrl+S")));
pannelStyle->addLargeAction(actSave);
//这样设置快捷键
QShortcut* shortCut = new QShortcut(QKeySequence(QLatin1String("Ctrl+S")), this);
connect(shortCut, &QShortcut::activated, this, [ actSave ]() { actSave->trigger(); });
//这样设置是无效的
// actSave->setShortcut(QKeySequence(QLatin1String("Ctrl+S")));

connect(actSave, &QAction::triggered, this, [ this ](bool b) {
Q_UNUSED(b);
this->mTextedit->append("actSaveion clicked");
});
pannelStyle->addLargeAction(actSave);

QAction* actHideRibbon = createAction(tr("hide ribbon"), ":/icon/icon/hideRibbon.svg", "actHideRibbon");
actHideRibbon->setCheckable(true);
Expand Down Expand Up @@ -1065,6 +1071,7 @@ void MainWindow::createContextCategoryPage1(SARibbonCategory* page)

mActionUnlock = createAction(tr("unlock"), ":/icon/icon/unlock.svg");
mActionUnlock->setShortcut(QKeySequence(QLatin1String("Ctrl+E")));
mActionUnlock->setShortcutContext(Qt::ApplicationShortcut);
pannel->addLargeAction(mActionUnlock);
connect(mActionUnlock, &QAction::triggered, this, [ this ](bool b) {
Q_UNUSED(b);
Expand All @@ -1079,6 +1086,7 @@ void MainWindow::createContextCategoryPage1(SARibbonCategory* page)

mActionSetTextTest->setCheckable(true);
mActionSetTextTest->setShortcut(QKeySequence(QLatin1String("Ctrl+D")));
mActionSetTextTest->setShortcutContext(Qt::ApplicationShortcut);
pannel->addLargeAction(mActionSetTextTest);

connect(mActionSetTextTest, &QAction::toggled, this, [ this ](bool b) {
Expand All @@ -1095,7 +1103,7 @@ void MainWindow::createContextCategoryPage1(SARibbonCategory* page)
pannel->addLargeAction(mActionShowTest);

mPannelVisbileExample = page->addPannel(tr("show/hide"));

//重复添加
mPannelVisbileExample->addLargeAction(mActionSetTextTest);

connect(mActionShowTest, &QAction::toggled, this, [ this ](bool b) {
Expand Down

0 comments on commit c754b20

Please sign in to comment.