Skip to content

Commit

Permalink
调整例子
Browse files Browse the repository at this point in the history
  • Loading branch information
czyt1988 committed Jan 2, 2024
1 parent 03fb027 commit 31d91f6
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 12 deletions.
17 changes: 10 additions & 7 deletions src/SARibbonBar/SARibbonMainWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,13 @@ SARibbonBar* SARibbonMainWindow::ribbonBar() const
return qobject_cast< SARibbonBar* >(menuWidget());
}

#if !SARIBBON_USE_3RDPARTY_FRAMELESSHELPER
#if SARIBBON_USE_3RDPARTY_FRAMELESSHELPER
FRAMELESSHELPER_PREPEND_NAMESPACE(FramelessWidgetsHelper*) SARibbonMainWindow::framelessHelper()
{
return FramelessWidgetsHelper::get(this);
}
#else

SAFramelessHelper* SARibbonMainWindow::framelessHelper()
{
return (d_ptr->mFramelessHelper);
Expand All @@ -110,11 +116,6 @@ bool SARibbonMainWindow::eventFilter(QObject* obj, QEvent* e)
}
return (QMainWindow::eventFilter(obj, e));
}
#else
FRAMELESSHELPER_PREPEND_NAMESPACE(FramelessWidgetsHelper*) SARibbonMainWindow::framelessHelper()
{
return FramelessWidgetsHelper::get(this);
}
#endif
/**
* @brief 此函数仅用于控制最小最大化和关闭按钮的显示
Expand Down Expand Up @@ -317,7 +318,9 @@ void SARibbonMainWindow::setupNormalWindow()
d_ptr->mWindowButtonGroup = new SAWindowButtonGroup(this);
}
d_ptr->mWindowButtonGroup->setWindowStates(windowState());
d_ptr->mWindowButtonGroup->resize(60, 30);
d_ptr->mWindowButtonGroup->show();
d_ptr->mWindowButtonGroup->raise();
#endif
}

Expand Down Expand Up @@ -348,6 +351,6 @@ void sa_set_ribbon_theme(QWidget* w, SARibbonMainWindow::RibbonTheme theme)
return;
}
// 有反馈用qstring接住文件内容,再设置进去才能生效(qt5.7版本)
QString qss = file.readAll();
QString qss = QString::fromUtf8(file.readAll());
w->setStyleSheet(qss);
}
13 changes: 12 additions & 1 deletion src/example/NormalMenuBarExample/MainWindow.cpp
Original file line number Diff line number Diff line change
@@ -1,12 +1,23 @@
#include "MainWindow.h"
#include "ui_MainWindow.h"

#if SARIBBON_USE_3RDPARTY_FRAMELESSHELPER
#include "FramelessHelper/Widgets/standardsystembutton.h"
#include "FramelessHelper/Widgets/framelesswidgetshelper.h"
FRAMELESSHELPER_USE_NAMESPACE
using namespace Global;
#endif
MainWindow::MainWindow(QWidget* parent) : SARibbonMainWindow(parent, false)
{
if (!isUseRibbon()) {
ui = new Ui::MainWindow;
ui->setupUi(this);
}
#if SARIBBON_USE_3RDPARTY_FRAMELESSHELPER
if (QWidget* w = menuWidget()) {
auto fh = framelessHelper();
fh->setHitTestVisible(w);
}
#endif
}

MainWindow::~MainWindow()
Expand Down
8 changes: 4 additions & 4 deletions src/example/WidgetWithRibbon/Widget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,12 @@ Widget::Widget(QWidget* parent) : QWidget(parent), ui(new Ui::Widget)
mRibbonBar->setRibbonStyle(SARibbonBar::RibbonStyleCompactThreeRow);
// 取消applicationbutton
mRibbonBar->setApplicationButton(nullptr);
//设置主题,这里虽然没用到SARibbonMainWindow,但Ribbon的主题是SARibbonMainWindow中定义的,因此要引入SARibbonMainWindow.h
// 设置主题,这里虽然没用到SARibbonMainWindow,但Ribbon的主题是SARibbonMainWindow中定义的,因此要引入SARibbonMainWindow.h
sa_set_ribbon_theme(mRibbonBar, SARibbonMainWindow::RibbonThemeOffice2013);

// QWidgets设置一个QVBoxLayout,把窗口放到QVBoxLayout的第二个布局中,第一个布局给SARibbonBar
// 这样,SARibbonBar就会在最上面
ui->verticalLayout->insertWidget(0, mRibbonBar);
// QLayout有专门的setMenuBar接口,针对menubar的布局,不需要插入到verticalLayout的0位置也可以实现
// ui->verticalLayout->insertWidget(0, mRibbonBar);
ui->verticalLayout->setMenuBar(mRibbonBar);

buildRibbon(mRibbonBar);
}
Expand Down

0 comments on commit 31d91f6

Please sign in to comment.