Giter VIP home page Giter VIP logo

Comments (6)

czyt1988 avatar czyt1988 commented on August 13, 2024

SARibbonBar::RibbonStyle中有4种模式,其中以TwoRow结尾的是可以指定文本是否换行,非TwoRow结尾都是会换行,决定是否换行通过静态函数:SARibbonToolButton::setLiteStyleEnableWordWrap来设置,这个函数需要在构建ui之前调用,否则需要全部刷新才看到效果。在例子中有相关例子,由于我在用手机没法给你截图。
例子里面有个word wrap in 2row的按钮,切换后需要切换一下ribbon的style,强制重新计算尺寸才能看到效果

from saribbon.

AndyYangjd avatar AndyYangjd commented on August 13, 2024

我这边选用的是wps风格(非两行),我这边发现三行模式下是否换行好像是跟文字的长度有关。当文字长度足够长的时候才会换行。是否有一些机制(检验到字符串中间有空格),可以强制三行模式下换行?

测试如下图所示:
图片

我是将mainwindow.cpp中的部分代码修改如下:

# 修改save按扭的字符串
 QAction* actSave = createAction(tr("New Terminal"), ":/icon/icon/save.svg");

# 修改 show context 的字符串
QAction* actShowContext = createAction(tr("new Script"), ":/icon/icon/showContext.svg");

# 修改 delete context 的字符串
QAction* actDeleteContext = createAction(tr("create Script"), ":/icon/icon/deleteContext.svg");

Plus: 刚发现了一种解决方案,代码如下图:

# 在new和script中间空格多一些
QAction* act_new_script= createAction(tr("new               Script"), ":/image/image/save.png");

结果如下图:
图片

from saribbon.

AndyYangjd avatar AndyYangjd commented on August 13, 2024

一个新的问题是我这边用Qt6.2无法编译成功,只能用Qt5.15编写

from saribbon.

czyt1988 avatar czyt1988 commented on August 13, 2024

qt6没试过,你可以提到新的issues里,我专门处理一下

from saribbon.

czyt1988 avatar czyt1988 commented on August 13, 2024

我这边选用的是wps风格(非两行),我这边发现三行模式下是否换行好像是跟文字的长度有关。当文字长度足够长的时候才会换行。是否有一些机制(检验到字符串中间有空格),可以强制三行模式下换行?

测试如下图所示: 图片

我是将mainwindow.cpp中的部分代码修改如下:

# 修改save按扭的字符串
 QAction* actSave = createAction(tr("New Terminal"), ":/icon/icon/save.svg");

# 修改 show context 的字符串
QAction* actShowContext = createAction(tr("new Script"), ":/icon/icon/showContext.svg");

# 修改 delete context 的字符串
QAction* actDeleteContext = createAction(tr("create Script"), ":/icon/icon/deleteContext.svg");

Plus: 刚发现了一种解决方案,代码如下图:

# 在new和script中间空格多一些
QAction* act_new_script= createAction(tr("new               Script"), ":/image/image/save.png");

结果如下图: 图片

换行的确和文字长度有关,在src/SARibbonBar/SARibbonToolButton.cpp中,会对文字长度进行评估,可见:void SARibbonToolButton::reCalcSizeHint(QSize s)的这一段:

//! 1 先获取最优的文字textRange
                {
                    const int maxTrycount = 3;
                    int trycount          = 0;
                    int alignment         = Qt::TextShowMnemonic | Qt::TextWordWrap;
                    do {
                        //先计算两行文本的紧凑矩形
                        //从一半开始逐渐递增
                        textRange.setWidth(s.width() / 2 + (s.width() / 2) * (float(trycount) / maxTrycount));
                        textRange = fm.boundingRect(textRange, alignment, text());
                        if (textRange.height() <= (fm.lineSpacing() * 2)) {
                            //保证在两行
                            m_isWordWrap = (textRange.height() > fm.lineSpacing());
                            break;
                        }
                        ++trycount;
                    } while (trycount < 3);
                }

我会尝试3次,以保证得到一个较为紧凑的文本

from saribbon.

AndyYangjd avatar AndyYangjd commented on August 13, 2024

好的,感谢

from saribbon.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.