gpt4 book ai didi

qt - 如何在 QML 中使用 Font Awesome

转载 作者:行者123 更新时间:2023-12-04 19:51:15 27 4
gpt4 key购买 nike

有谁知道如何在 QML 中使用 Font Awesome?我找不到任何文档或任何有关如何在 QML 中使用 Font Awesome 的信息。

最佳答案

我喜欢做的是使用 fontello创建一组最小的图标,而不是从 FontAwesome 下载整个图标集。使用 texteditor示例作为引用:

  • 下载字体并将其存储在项目目录中的某个位置。在示例中,它位于 fonts文件夹。
  • 如果您在项目中使用 .qrc 文件,请将其添加到 one of those .
  • 我可以想到两种方法来在您的 QML 中识别字体: FontLoader QFontDatabase::addApplicationFont() .使用 QFontDatabase::addApplicationFont() , 添加 this加载应用程序的 QML 之前的代码:
    QFontDatabase fontDatabase;
    if (fontDatabase.addApplicationFont(":/fonts/fontello.ttf") == -1)
    qWarning() << "Failed to load fontello.ttf";
  • 使用 Unicode codestext whatever item 的属性(property)您想在以下位置显示图标:
    ToolButton {
    id: openButton
    text: "\uF115" // icon-folder-open-empty
    font.family: "fontello"
    onClicked: openDialog.open()
    }
  • 关于qt - 如何在 QML 中使用 Font Awesome,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47788300/

    27 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com