Skip to content

Commit

Permalink
添加了SARibbonBar::initHighDpi()静态函数,方便开启高分屏设置
Browse files Browse the repository at this point in the history
  • Loading branch information
czyt1988 committed Jan 9, 2024
1 parent ea2aa0b commit a5772c3
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 9 deletions.
9 changes: 8 additions & 1 deletion changlog.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,14 @@
4.属性pannelLayoutMode,可控制pannel的布局方式
5.属性tabOnTitle,可控制tab放置在title栏上
6.titleBarHeight,tabBarHeight,categoryHeight这三个高度支持用户自定义,默认会根据字体大小计算
6.setTabBarBaseLineColor控制tabbar下基线颜色,某些主题需要设置颜色(窗口标题栏和category区域颜色一样的情况下如office 2013主题)可通过此函数设置,传入QColor()取消颜色
7.setTabBarBaseLineColor控制tabbar下基线颜色,某些主题需要设置颜色(窗口标题栏和category区域颜色一样的情况下如office 2013主题)可通过此函数设置,传入QColor()取消颜色
- 添加了SARibbonBar::initHighDpi()静态函数,方便开启高分屏设置
- 【注意】frameless库更换为qwindowkit(https://github.com/stdware/qwindowkit),qwindowkit源码不作为项目一部分,使用git submodule管理,因此,项目clone下来后,需要执行`git submodule update --init --recursive`
- 【注意】如果开启SARIBBON_USE_FRAMELESS_LIB(默认开启),需要先构建`qwindowkit`,目前`qwindowkit`不提供qmake,只提供cmake,编译完`qwindowkit`后,SARibbon支持qmake和cmake
- SAMainWindow支持非ribbon模式

【警告】编译过程会在当前目录下生成bin_qtx.x.x_Debug/Release_x64/86这样的文件夹,请确保有写入权限,否则会执行qmake或cmake过程报错



由于接口函数有明显调整,因此版本变更为2.0
Expand Down
23 changes: 23 additions & 0 deletions src/SARibbonBar/SARibbonBar.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -529,6 +529,29 @@ QList< QColor > SARibbonBar::defaultContextCategoryColorList()
return res;
}

/**
* @brief 提供高分屏的支持静态函数
*
* @note 此函数需要在main函数,QApplication生成之前调用
* @code
* int main(int argc, char* argv[]){
* SARibbonBar::initHighDpi();
* QApplication a(argc, argv);
* ...
* }
* @endcode
*/
void SARibbonBar::initHighDpi()
{
#if (QT_VERSION >= QT_VERSION_CHECK(5, 6, 0)) && (QT_VERSION < QT_VERSION_CHECK(6, 0, 0))
QApplication::setAttribute(Qt::AA_EnableHighDpiScaling);
QApplication::setAttribute(Qt::AA_UseHighDpiPixmaps);
#endif
#if (QT_VERSION >= QT_VERSION_CHECK(5, 14, 0))
QApplication::setHighDpiScaleFactorRoundingPolicy(Qt::HighDpiScaleFactorRoundingPolicy::PassThrough);
#endif
}

/**
* @brief 返回applicationButton
* @return 默认的applicationButton是@ref SARibbonApplicationButton 生成,通过@ref setApplicationButton 可设置为其他button
Expand Down
3 changes: 3 additions & 0 deletions src/SARibbonBar/SARibbonBar.h
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,9 @@ class SA_RIBBON_EXPORT SARibbonBar : public QMenuBar
// 获取默认的上下文标签颜色列表
static QList< QColor > defaultContextCategoryColorList();

//
static void initHighDpi();

public:
// 构造函数
SARibbonBar(QWidget* parent = nullptr);
Expand Down
11 changes: 3 additions & 8 deletions src/example/MainWindowExample/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
#include <QApplication>
#include <QDebug>
#include <QElapsedTimer>

#include "SARibbonBar.h"
// 重定向qdebug的打印
void log_out_put(QtMsgType type, const QMessageLogContext& context, const QString& msg);

Expand Down Expand Up @@ -46,13 +46,8 @@ void log_out_put(QtMsgType type, const QMessageLogContext& context, const QStrin
int main(int argc, char* argv[])
{
// 以下是针对高分屏的设置,有高分屏需求都需要按照下面进行设置
#if (QT_VERSION >= QT_VERSION_CHECK(5, 6, 0))
QApplication::setAttribute(Qt::AA_EnableHighDpiScaling);
QApplication::setAttribute(Qt::AA_UseHighDpiPixmaps);
#endif
#if (QT_VERSION >= QT_VERSION_CHECK(5, 14, 0))
QApplication::setHighDpiScaleFactorRoundingPolicy(Qt::HighDpiScaleFactorRoundingPolicy::PassThrough);
#endif
SARibbonBar::initHighDpi();

QApplication a(argc, argv);
qInstallMessageHandler(log_out_put);
QFont f = a.font();
Expand Down

0 comments on commit a5772c3

Please sign in to comment.